我正在尝试在自己的Node.js应用程序中实现我自己的普罗米修斯度量标准,但是我无法弄清楚为什么它无法在getMetrics()
方法中返回我的自定义度量标准,如下类所示:>
import { Injectable } from '@nestjs/common';
import { collectDefaultMetrics, Counter, metric, Registry } from 'prom-client';
@Injectable()
export class PrometheusService {
private register: Registry;
private restRequestCounter: Counter;
constructor() {
this.register = new Registry();
collectDefaultMetrics({ register: this.register });
this.restRequestCounter = new Counter({
name: 'incoming_rest_request_count',
help: 'Number of all incoming http requests for this service'
});
}
public incrementHttpRequestCount(): void {
this.restRequestCounter.inc(1);
}
public getMetrics(): metric[] {
return this.register.getMetricsAsJSON();
}
}
它仅返回所有“ defaultMetrics”。我在做什么错了?
答案 0 :(得分:1)
使用:
this.register.metrics()
功能将是:
public getMetrics(): metric[] {
return this.register.metrics();
}