nestjs-metrics-reporter is a lightweight, zero-setup solution for efficiently reporting Prometheus metrics in your NestJS application. With no dependency injection required, you can effortlessly track application metrics from anywhere in your codebase, streamlining your monitoring and observability processes.
๐ NestJS Metrics Reporter is a powerful, zero-dependency-injection Prometheus metrics solution designed specifically for NestJS applications. This lightweight tool enables developers to effortlessly report metrics from any part of their codebase without the hassle of complex setup or cumbersome dependency management.
The nestjs-metrics-reporter library is your go-to solution for streamlining metrics reporting in NestJS. It simplifies the process by allowing immediate metrics access through a global static reporter, eliminating the need for dependency injection or extensive configurations.
Incorporate this powerful tool into your application with just a few lines of code:
import { ReporterService } from 'nestjs-metrics-reporter';
ReporterService.counter('api_requests_total', { endpoint: '/users' });
Begin with minimal setup by importing the ReporterModule in your application's AppModule:
import { Module } from "@nestjs/common";
import { ReporterModule } from 'nestjs-metrics-reporter';
@Module({
imports: [
ReporterModule.forRoot({
defaultMetricsEnabled: true,
defaultLabels: {
app: 'my-app',
environment: 'production',
},
// Add optional configurations here
}),
],
})
export class AppModule {
}
Once initialized, you can report metrics from any location throughout your application:
import { Injectable } from '@nestjs/common';
import { ReporterService } from 'nestjs-metrics-reporter';
@Injectable()
export class UserService {
async createUser() {
ReporterService.counter('users_created_total', {
source: 'api',
user_type: 'standard'
});
ReporterService.gauge('active_users', 42, {
region: 'us-east-1'
});
await ReporterService.pushMetrics('user_service_job');
}
}
Utilize the global static service for reporting metrics with ease:
| Method | Description | Parameters |
|---|---|---|
counter() | Increment a counter metric | `key: string, labels?: Record<string, string |
gauge() | Set a gauge value | `key: string, value: number, labels?: Record<string, string |
histogram() | Record a histogram value | `key: string, value: number, labels?: Record<string, string |
summary() | Record a summary value | `key: string, value: number, labels?: Record<string, string |
pushMetrics() | Push metrics to Pushgateway | jobName: string |
We welcome contributions! Check our Contributing Guide for more details on getting involved.
No comments yet.
Sign in to be the first to comment.