简体   繁体   English

prometheus端点调用时如何触发Metrics计算

[英]How to trigger Metrics calculation at the time of prometheus endpoint call

I am trying to configure my Micronaut Application with Micrometer and Prometheus.我正在尝试使用 Micrometer 和 Prometheus 配置我的 Micronaut 应用程序。 I want to do some calculation at the time of prometheus endpoint call.我想在普罗米修斯端点调用时做一些计算。 Can someone guide me here?有人可以在这里指导我吗?

I tried to define a bean in Micronaut as follows, but it didn't get triggered and no metric with name SampleMetric was there:我试图在 Micronaut 中定义一个 bean,如下所示,但它没有被触发,并且没有名称为 SampleMetric 的度量:

@Prototype
public class MyBean {

  @Inject
  MeterRegistry registry;

  public MyBean() {
    Gauge.builder("SampleMetric", 12).register(registry);
    // I also tried the following but that also didn't work
    //registry.gauge("SampleMetric", 12);
  }
}

Thanks in advance提前致谢

Gauge s are queried every time the Prometheus registry is scraped (prometheus endpoint call).每次爬取 Prometheus 注册表时都会查询Gauge (prometheus 端点调用)。 Also Gauge supports providing your own state object and own method that fetches the current value, please see the docs: https://micrometer.io/docs/concepts#_gauge_fluent_builder Gauge还支持提供您自己的 state object 和自己的获取当前值的方法,请参阅文档: https#micrometer.io/ docs/concepts

If you follow the example in the docs:如果您按照文档中的示例进行操作:

Gauge.builder("gauge", myObj, myObj::gaugeValue).register(registry);

myObj.gaugeValue() is called every time the prometheus endpoint is called.每次调用 prometheus 端点时都会调用myObj.gaugeValue()

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

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