英文:
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:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
</parent>
with
<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>
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 '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)
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要求具有相同名称的所有指标具有相同的标签键集。已经存在一个名为'jvm_gc_pause_seconds'的现有指标,其中包含标签键[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 'jvm_gc_pause_seconds' 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论