Nestjs metric module
yarn add @qiwi/nestjs-enterprise-metric
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule)
metricService = app.get('IMetricService')
metricService.attach(getNodeMetrics)
// ...etc
}
import {
GraphiteService,
MetricDecorator,
MetricService,
ErrorDecorator,
MeteredDecorator,
RequestRateDecorator,
} from '@qiwi/nestjs-enterprise-metric'
import {Controller, Get, Module} from "@nestjs/common";
@Controller()
export class TestClassController {
@Get('MeteredDecorator')
@MetricDecorator('Controller')
async test() {
return 'foo'
}
@Get('ErrorDecorator')
@ErrorDecorator('Controller')
async error() {
return 'foo'
}
@Get('MeteredDecorator')
@MeteredDecorator('Controller')
async meter() {
return 'foo'
}
@Get('RequestRateDecorator')
@RequestRateDecorator('Controller')
async rate() {
return 'foo'
}
}
@Module({
controllers: [TestClassController],
providers: [{
provide: 'IMetricService',
useFactory: (graphiteService)=>{
return new MetricService(graphiteService, {prefix: '$some$your$metric', interval: 1000})
},
inject: ['IGraphiteService']
}, {
provide: 'IGraphiteService',
useFactory: ()=>{
return new GraphiteService('yourGraphiteApiEndpoint')
}
}]
})
export class AppModule {}
Exports MetricService
with token IMetricService
The decorator measures the number of error events and also tracks 1-, 5-, and 15-minute moving averages.
The decorator measures the number of function calls and also tracks 1-, 5-, and 15-minute moving averages.
The decorator collects statistically significant query processing times skewed toward the last 5 minutes to examine their distribution.
Union ErrorDecorator, MeteredDecorator and RequestRateDecorator
Attach your metric
Return process and os metric.