Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@willsoto/nestjs-prometheus

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@willsoto/nestjs-prometheus

NestJS module for Prometheus

  • 6.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132K
decreased by-2.22%
Maintainers
1
Weekly downloads
 
Created

What is @willsoto/nestjs-prometheus?

@willsoto/nestjs-prometheus is a NestJS module that integrates Prometheus metrics into your NestJS application. It allows you to easily create and manage Prometheus metrics, providing a way to monitor the performance and health of your application.

What are @willsoto/nestjs-prometheus's main functionalities?

Basic Setup

This code demonstrates how to set up the Prometheus module in a NestJS application. By importing and registering the PrometheusModule, you can start collecting metrics.

const { Module } = require('@nestjs/common');
const { PrometheusModule } = require('@willsoto/nestjs-prometheus');

@Module({
  imports: [PrometheusModule.register()],
})
class AppModule {}

Custom Metrics

This code demonstrates how to create and use custom metrics in your NestJS application. In this example, a custom counter metric named 'my_counter' is created and incremented within a service.

const { Injectable } = require('@nestjs/common');
const { InjectMetric, makeCounterProvider } = require('@willsoto/nestjs-prometheus');
const { Counter } = require('prom-client');

@Injectable()
class MyService {
  constructor(@InjectMetric('my_counter') private counter: Counter<string>) {}

  incrementCounter() {
    this.counter.inc();
  }
}

const { Module } = require('@nestjs/common');
@Module({
  providers: [
    MyService,
    makeCounterProvider({
      name: 'my_counter',
      help: 'Example of a custom counter',
    }),
  ],
})
class AppModule {}

HTTP Metrics

This code demonstrates how to set up HTTP metrics to track the total number of HTTP requests. The counter metric 'http_requests_total' is created with labels for method and status.

const { Module } = require('@nestjs/common');
const { PrometheusModule, makeCounterProvider } = require('@willsoto/nestjs-prometheus');

@Module({
  imports: [PrometheusModule.register()],
  providers: [
    makeCounterProvider({
      name: 'http_requests_total',
      help: 'Total number of HTTP requests',
      labelNames: ['method', 'status'],
    }),
  ],
})
class AppModule {}

Other packages similar to @willsoto/nestjs-prometheus

FAQs

Package last updated on 06 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc