简体   繁体   English

自定义直方图指标未显示在普罗米修斯中

[英]Custom histogram metrics not showing up in prometheus

I am trying to add a merics in my plain java class in a spring app, like explained here我正在尝试在 spring 应用程序中的 spring 应用程序中的普通 java class 中添加一个merics,如解释

static final Histogram requestLatency = Histogram.build()
        .name("my_custom_service_method_latency_seconds")
        .help("Request latency in seconds for my_custom_service

.").register();

...and then in method: ...然后在方法中:

Histogram.Timer requestTimer = requestLatency.startTimer();

try{
....

}finally{
    requestTimer.observeDuration();
}

But on prometheus dashboard I see no such metrics.但在普罗米修斯仪表板上,我看不到这样的指标。

Am I missing something here?我在这里错过了什么吗?

Edit: In application.properties, I have:编辑:在 application.properties 中,我有:

management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.endpoint.health.show-details=always

Issue for me was using the default .register() method which is using the defaultRegisty :对我来说问题是使用默认的.register()方法,该方法正在使用defaultRegisty

public C register() {
  return register(CollectorRegistry.defaultRegistry);
}

Here is the code that worked for me (after injection of CollectorReqistry ):这是对我有用的代码(在注入CollectorReqistry之后):

              Histogram.build()
                  .name("requests_latency")
                  .help("Request latency in seconds.")
                  .buckets(50.0, 100.0, 150.0, 200.0, 250.0, 300.0)
                  .labelNames("my label")
                  .register(collectorRegistry);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM