Actuator Prometheus 的自定义指标

Custom Metrics for Actuator Prometheus

我已经激活了 spring 执行器普罗米修斯端点 /actuator/prometheus。通过添加千分尺和执行器的依赖项并启用普罗米修斯端点。我如何获得自定义指标?

您需要在 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 /prometheus URL。添加后缀 "total" 以符合 Prometheus 命名约定。