How to specify a whitelist of the metrics I want to use in spring-boot with micrometer

十年热恋 提交于 2019-12-23 07:47:04

问题


We want to use only some of the given metrics from micrometer in our spring-boot application. We find the following code-snippet in the docs. This should disable all metrics by default and should enable us to create a whitelist of possible metrics.

Spring blog about Micrometer metrics

management.metrics.enable.root=false
management.metrics.enable.jvm=true

The problem is, that it doesn't work. All existing metrics are written to our graphite instance.

We found already a workaround but we would like to edit our metrics in our property files.

This is our current workaround:

@Configuration
public class MicrometerGraphiteConfig {

    @Bean
    public MeterRegistryCustomizer<MeterRegistry> commonTags() {
        return registry -> registry
            .config()
            .meterFilter(MeterFilter.denyUnless(this::isMetricToInclude))
            .commonTags("a_tag", "some_common_tags");
    }

    private boolean isMetricToInclude(Meter.Id id) {
        return id.getName().startsWith("jvm.");
    }
}

Do anyone has any experience to share, what we have to think of to reach this goal within the property-file configuration?


回答1:


You need to use management.metrics.enable.all=false not management.metrics.enable.root=false as that property has been removed. I had the same requirement to whitelist the metrics and just choose the required ones. The blog post is out of date and was advised to use management.metrics.enable.all=false by the Spring Boot devs on gitter.



来源:https://stackoverflow.com/questions/54422023/how-to-specify-a-whitelist-of-the-metrics-i-want-to-use-in-spring-boot-with-micr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!