【问题标题】:Custom Metrics for Actuator PrometheusActuator Prometheus 的自定义指标
【发布时间】:2018-10-28 14:21:57
【问题描述】:

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

【问题讨论】:

    标签: java spring-boot metrics prometheus spring-boot-actuator


    【解决方案1】:

    您需要在 Micrometer Registry 中注册您的指标。

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2021-06-16
    • 2020-03-31
    • 1970-01-01
    相关资源
    最近更新 更多