我已经激活了弹簧执行器prometheus endpont / actuator / prometheus.通过添加千分尺和执行器的依赖关系并启用prometheus endpont.我如何获得自定义指标?
解决方法:
您需要使用Micrometer Registry注册您的指标.
以下示例在构造函数中创建度量标准. Micrometer注册表作为构造函数参数注入:
@Component
public class MyComponent {
private final Counter myCounter;
public MyComponent(MeterRegistry registry) {
myCounter = Counter
.builder("mycustomcounter")
.description("this is my custom counter")
.register(registry);
}
public String countedCall() {
myCounter.increment();
}
}
一旦可用,您将在/ prometheus URL中的注册表中获得指标mycustomcounter_total.添加后缀“total”以符合Prometheus命名约定.