简体   繁体   English

千分尺指标和 Application Insights java 代理 - 指标会累积,尽管它们不应该(或者我错过了什么)

[英]Micrometer metrics & Application Insights java agent - Metrics accumulate although they shouldn't (or am I missing something)

We have a Java EE JAX-RS application (Java EE 8 hosted on WildFly 20), in which we have configured Micrometer (v1.6.4) as a metrics framework.我们有一个 Java EE JAX-RS 应用程序(Java EE 8 托管在 WildFly 20 上),其中我们将 Micrometer (v1.6.4) 配置为度量框架。 We are trying to connect it with Azure Application Insights so that metrics are made available to the relevant Application Insights resource (and then add alerts etc.).我们正在尝试将其与 Azure Application Insights 连接,以便相关 Application Insights 资源可以使用指标(然后添加警报等)。

In order to do so, we have attached the codeless Application Insights agent (v3.0.2), which automatically publishes Micrometer metrics without any code changes.为此,我们附加了无代码 Application Insights 代理 (v3.0.2),该代理无需任何代码更改即可自动发布 Micrometer 指标。 On top of that, we have added a PrometheusMeterRegistry in the globalRegistry, only for debugging purposes (we do not use Prometheus).最重要的是,我们在 globalRegistry 中添加了一个 PrometheusMeterRegistry,仅用于调试目的(我们不使用 Prometheus)。

Metrics.globalRegistry.add(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT));

On top of that, we have configured an endpoint which returns the Prometheus data using the following snippet:最重要的是,我们配置了一个端点,它使用以下代码片段返回 Prometheus 数据:

PrometheusMeterRegistry promRegistry = (PrometheusMeterRegistry) registry;
result = promRegistry.scrape();

The agent has a configuration file attached to it in which only the connectionString and role name of the application are set.代理附加了一个配置文件,其中仅设置了应用程序的连接字符串和角色名称。

The agent starts correctly, and data are published in the Application Insights resource.代理正确启动,并且数据在 Application Insights 资源中发布。 Custom metrics are available for selection in the Monitoring -> Metrics area of the resource.自定义指标可在资源的 Monitoring -> Metrics 区域中选择。

The issue we are facing is that the metrics data accumulate over time although they shouldn't.我们面临的问题是指标数据会随着时间的推移而累积,尽管它们不应该如此。 And to give an example:并举个例子:

  • We have a Timer setup in order to measure time of a specific operation in our application.我们有一个定时器设置来测量我们应用程序中特定操作的时间。 The Timer is triggered by an @Interceptor using the @AroundInvoke method, and records the time take for the actual operation to complete. Timer 由@Interceptor 使用@AroundInvoke 方法触发,并记录实际操作完成所需的时间。 We use this code snippet to record the time我们使用这个代码片段来记录时间
...
Builder timerBuilder = Timer.builder(timerName);
Timer timer = timerBuilder.register(metricsProducer.getMetricsRegistry());

return timer.record(() -> {
    try {
        return ctx.proceed();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
});
  • We have a Counter also setup which is used to measure the number of times that a specific operation has been called (I know that the same can be achieved through the Timer, but it's only there for testing purposes)我们还有一个 Counter 设置,用于测量调用特定操作的次数(我知道可以通过 Timer 实现相同的操作,但它仅用于测试目的)

Assume that we call the operation that is bound to the Counter only once.假设我们只调用一次绑定到 Counter 的操作。 We expect that the Counter value is 1, which is something that we confirm with logging.我们期望 Counter 值为 1,这是我们通过日志记录确认的。 Assume also that we call the operation that is bound to the Timer only once.还假设我们只调用一次绑定到 Timer 的操作。 We expect that only this triggering gets measured and recorded.我们期望只有这种触发被测量和记录。

In the Application Insights resource, we see that the metric information gets updated every time the agent publishes information, and modifies the values without though any trigger in the backend.在 Application Insights 资源中,我们看到每次代理发布信息时都会更新指标信息,并在后端没有任何触发器的情况下修改值。 In particular, both of the metrics increase the Count aggregated value, but since for the Timer the duration does not change, the Average falls (suggesting that a metric value is passed with duration 0).特别是,这两个指标都会增加 Count 聚合值,但由于 Timer 的持续时间不会改变,因此平均值会下降(表明通过持续时间 0 的指标值)。

On the other hand, when calling the Prometheus scraping endpoint, data are returned correctly, ie Count for both of the metrics stays to 1 and data are the expected ones.另一方面,当调用 Prometheus 抓取端点时,数据被正确返回,即两个指标的 Count 都保持为 1,并且数据是预期的。

I have tried the same using SpringBoot as the underlying framework, again with the same results.我已经尝试过使用 SpringBoot 作为底层框架,再次获得相同的结果。

Any thoughts?有什么想法吗? Am I missing something?我错过了什么吗?

Thank you谢谢

Vangelis万吉利斯

It's an issue in micrometer library, and a relevant PR has been created这是千分尺库中的一个问题,并且已经创建了一个相关的PR

Is it possible that this issue in Micrometer is related to what I describe here ?千分尺中的这个问题是否可能与我在这里描述的有关?

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

相关问题 Azure Application Insights 在使用 Java 8 和应用程序洞察力 SDK 1.0.8 版时不显示实时指标 - Azure Application Insights doesn't show live metrics when using Java 8 and application insights SDK version 1.0.8 在 Java springboot 应用程序中使用千分尺收集 HikariCp 指标,方法是在 - HikariCp metrics collection using micrometer in Java springboot application by configuring it in 使用Micrometer指标运行SpringBoot 2应用程序时出错 - Error when running SpringBoot 2 application with Micrometer metrics jersey 应用程序中的千分尺 Prometheus 指标(非弹簧) - Micrometer Prometheus metrics in jersey application (Non spring) 使用 spring java 的千分尺指标(没有 spring boot) - Micrometer metrics with spring java (NO spring boot) Java Micrometer - 如何处理 *_bucket 类型的指标 - Java Micrometer - What to do with metrics of type *_bucket 如何更改千分尺中的指标命名 - How can I change metrics naming in Micrometer 自 SpringBoot 2.3.x 以来,千分尺中缺少 kafka 指标 - kafka metrics missing in micrometer since SpringBoot 2.3.x 从 jar 获取千分尺指标到 spring 引导应用程序 - Getting micrometer metrics from a jar to a spring boot application Java中的字体指标不正确/缺失? - Incorrect / missing font metrics in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM