-
Notifications
You must be signed in to change notification settings - Fork 2
/
provider.ts
29 lines (26 loc) · 871 Bytes
/
provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {Metric} from 'prom-client';
import {Provider} from '@nestjs/common';
import {Metrics} from '../enum';
import {PrometheusMetricOptions} from './options';
import {getPrometheusMetric, getToken} from './utils';
/**
* ```typescript
* import { Module } from "@nestjs/common";
* import { MetricsModule, Metric } from "@mists/nestjs-metrics";
* import { makePrometheusProvider } from "@mists/nestjs-metrics/dist/prometheus";
*
* @Module({
* imports: [MetricsModule.register()],
* providers: [makePrometheusProvider(Metric.Counter, 'metrics_prometheus_counter')],
* })
* export class AppModule {}
* ```
*/
export function makePrometheusProvider(type: Metrics, options: PrometheusMetricOptions): Provider {
return {
provide: getToken(options.name),
useFactory(): Metric<string> {
return getPrometheusMetric(type, options);
},
};
}