gpt4 book ai didi

java - Actuator Prometheus 的自定义指标

转载 作者:行者123 更新时间:2023-12-04 10:46:41 27 4
gpt4 key购买 nike

我已经激活了 Spring 执行器 prometheus endpont /actuator/prometheus .通过添加千分尺和执行器的依赖项并启用 prometheus 端点。我怎样才能获得自定义指标?

最佳答案

您需要使用 Micrometer Registry 注册您的指标。

以下示例在构造函数中创建指标。千分尺注册表作为构造函数参数注入(inject):

@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 命名约定。

关于java - Actuator Prometheus 的自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50406296/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com