来自Java(Spring Actuator)的Prometheus错误。

huangapple go评论142阅读模式
英文:

Error from promtheus in java (spring acuator)

问题

我在我的 Spring Boot 应用程序中启用并配置了带有 Prometheus 端点的 Spring Actuator。但是我收到一个错误消息,错误消息指出 Prometheus 要求具有相同名称的所有计量器具有相同的一组标签键。但不幸的是,Spring Actuator 不会为 jvm_gc_pause_seconds 执行这个操作。

我正在使用:

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.3.1.RELEASE</version>
</parent>

与以下依赖项:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

....

<dependency>
	<groupId>io.micrometer</groupId>
	<artifactId>micrometer-core</artifactId>
	<version>1.5.1</version>
</dependency>
<dependency>
	<groupId>io.micrometer</groupId>
	<artifactId>micrometer-registry-prometheus</artifactId>
	<version>1.5.1</version>
</dependency>

这是我的错误消息:

java.lang.IllegalArgumentException: Prometheus 要求具有相同名称的所有计量器具有相同的一组标签键。已经存在名为 'jvm_gc_pause_seconds' 的计量器。  
    at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$17(PrometheusMeterRegistry.java:429)  
    at java.base/java.util.concurrent.ConcurrentHashMap.compute(Unknown Source)  
    at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:413)  
    at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:196)  
    at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:308)  
    at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:612)  
    at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:566)  
    at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:306)  
    at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:539)  
    at io.micrometer.core.instrument.binder.jvm.JvmGcMetrics.lambda$bindTo$1(JvmGcMetrics.java:151)  
    at java.management/sun.management.NotificationEmitterSupport.sendNotification(Unknown Source)  
    at jdk.management/com.sun.management.internal.GarbageCollectorExtImpl.createGCNotification(Unknown Source)

有任何想法吗?!当我移除 Prometheus 端点配置 (micrometer-registry-prometheus 依赖) 时,我就没有这个错误。

英文:

I enabled and configured Spring Actuator with Prometheus endpoint in my spring boot application. But I receive an error, that Prometheus requires that all meters with the same name have the same set of tag keys. But unfortunately Spring Actuator won't do that for jvm_gc_pause_seconds.

I'm using:

&lt;parent&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
	&lt;version&gt;2.3.1.RELEASE&lt;/version&gt;
&lt;/parent&gt;

with

&lt;dependency&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;

....

&lt;dependency&gt;
	&lt;groupId&gt;io.micrometer&lt;/groupId&gt;
	&lt;artifactId&gt;micrometer-core&lt;/artifactId&gt;
	&lt;version&gt;1.5.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
	&lt;groupId&gt;io.micrometer&lt;/groupId&gt;
	&lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;
	&lt;version&gt;1.5.1&lt;/version&gt;
&lt;/dependency&gt;

This is my error message:

java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named &#39;jvm_gc_pause_seconds&#39;  │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$17(PrometheusMeterRegistry.java:429)                                                                       │
│     at java.base/java.util.concurrent.ConcurrentHashMap.compute(Unknown Source)                                                                                                            │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:413)                                                                                 │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:196)                                                                                         │
│     at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:308)                                                                                                  │
│     at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:612)                                                                                                │
│     at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:566)                                                                                        │
│     at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:306)                                                                                                           │
│     at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:539)                                                                                                                │
│     at io.micrometer.core.instrument.binder.jvm.JvmGcMetrics.lambda$bindTo$1(JvmGcMetrics.java:151)                                                                                        │
│     at java.management/sun.management.NotificationEmitterSupport.sendNotification(Unknown Source)                                                                                          │
│     at jdk.management/com.sun.management.internal.GarbageCollectorExtImpl.createGCNotification(Unknown Source)

Any idea?!
I don't have this error when I remove the Prometheus endpoint configuration (micrometer-registry-prometheus dependency).

答案1

得分: 3

我通过将micrometer-registry-prometheus从1.5.1版本升级到1.5.4版本来解决了我的问题。

通过此更新,错误消息更加易于理解:

Prometheus要求具有相同名称的所有指标具有相同的标签键集。已经存在一个名为&#39;jvm_gc_pause_seconds&#39;的现有指标,其中包含标签键[username,endpoint]。您要尝试注册的指标具有键[username,endpoint,service]。

因此,我找到了问题所在。我给所有指标添加了一个公共标签。在移除公共标签后,错误得以解决。

英文:

I solved my problem by updating micrometer-registry-prometheus from 1.5.1 to 1.5.4

With this update the error message was more speakable:

Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named &#39;jvm_gc_pause_seconds&#39; containing tag keys [username, endpoint]. The meter you are attempting to register has keys [username, endpoint, service].

So I found the problem. I added a common tag to all metrics. After removing the common tag, the error was solved.

huangapple
  • 本文由 发表于 2020年8月25日 17:22:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63575808.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定