Micronaut Micrometer Prometheus 通用标签配置不适用于所有指标

Micronaut Micrometer Prometheus common tag configuration is not applying to all metrics

Spring Boot 允许 common tags:

的声明式配置

Commons tags are applied to all meters and can be configured, as the following example shows:

management.metrics.tags.region=us-east-1

因此,在 Spring 引导中,management.metrics.tags.application=myapp 到位,所有指标都包含该标记,例如:

jvm_memory_max_bytes{application="myapp",area="heap",id="G1 Survivor Space"} -1.0
system_cpu_count{application="myapp"} 16.0

我想在 Micronaut 应用程序中实现相同的目的。似乎没有一种声明性的方式来做到这一点,相反,我们需要使用 MeterRegistryConfigurer.

programatically customize

我创建了以下内容:

@Singleton
@RequiresMetrics
class PrometheusMeterRegistryConfigurer: MeterRegistryConfigurer<MeterRegistry> {

    override fun configure(meterRegistry: MeterRegistry) {
        meterRegistry.config().commonTags("application", "myapp")
    }

    override fun getType(): Class<MeterRegistry> {
        return MeterRegistry::class.java
    }
}

问题是它没有将其应用于所有指标,一些指标被标记 (http_server_requests_seconds_max) 而其他指标则没有(jvm_memory_max_bytessystem_cpu_count 等) :

http_server_requests_seconds_max{application="myapp",exception="none",method="GET",status="200",uri="/actuator/prometheus",} 0.131942121
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'",} 1.22023936E8
system_cpu_count 16.0

如何使标签应用于所有 micrometer-prometheus 指标?

已解决添加两个不同的 MeterRegistryConfigurers:

@Singleton
@RequiresMetrics
class PrometheusMeterRegistryConfigurer: MeterRegistryConfigurer<PrometheusMeterRegistry> {

    override fun configure(meterRegistry: PrometheusMeterRegistry) {
        meterRegistry.config().commonTags("application", "myapp")
    }

    override fun getType(): Class<PrometheusMeterRegistry> {
        return PrometheusMeterRegistry::class.java
    }

}
@Singleton
@RequiresMetrics
class CompositeMeterRegistryConfigurer: MeterRegistryConfigurer<CompositeMeterRegistry> {

    override fun configure(meterRegistry: CompositeMeterRegistry) {
        meterRegistry.config().commonTags("application", "myapp")
    }

    override fun getType(): Class<CompositeMeterRegistry> {
        return CompositeMeterRegistry::class.java
    }
}