java中promtheus的错误(spring acuator)

flo*_*rox 5 java spring spring-boot-actuator prometheus actuator

我在 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>
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

这是我的错误信息:

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)
Run Code Online (Sandbox Code Playgroud)

任何的想法?!当我删除 Prometheus 端点配置(micrometer-registry-prometheus依赖项)时,我没有出现此错误。

flo*_*rox 3

micrometer-registry-prometheus我通过从 1.5.1更新到 1.5.4 解决了我的问题

通过此更新,错误消息更加明显:

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].
Run Code Online (Sandbox Code Playgroud)

所以我发现了问题所在。我为所有指标添加了一个通用标签。删除通用标签后,错误解决。