15

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?

PhilippB
  • 205
  • 2
  • 9

1 Answers1

13

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.

cb2
  • 146
  • 1
  • 4
  • Thanks for the reply, I will try that solution and let you know. – PhilippB Feb 19 '19 at 07:41
  • I have tried this solution and it worked fine. Thanks a lot. – PhilippB Apr 04 '19 at 06:31
  • @cb2 can you share a link of the Blog Post which shows how we can expose only a specific list of metrics that we want (something like whitelisting)? – alext Sep 30 '22 at 16:50
  • @sem10 blog is linked in original question but here is the relevant section: [meter-filters](https://spring.io/blog/2018/03/16/micrometer-spring-boot-2-s-new-application-metrics-collector#meter-filters) – cb2 Oct 01 '22 at 16:00
  • So if `management.metrics.enable.all=false` the use code to whitelist specific ones above will still work? – mal Aug 23 '23 at 10:12