Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 902
PhilippB Avatar asked Jan 29 '19 13:01

PhilippB


1 Answers

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.

like image 86
cb2 Avatar answered Sep 28 '22 02:09

cb2