Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable spring boot 2 default metrics

I have spring boot 2 REST application, with spring actuator enabled. by default spring generates a number of metrics (jvm, cpu, memory, etc) in /metrics endpoint. Apart from this I have used Micrometer APIs to create custom metrics. So far its been working really well.

Now, I have a requirement to generate only my custom metrics, but disable all the default metrics that spring provides. Note that I do not want to disable /metrics endpoint, but I want to disable only the default metrics.

Is this possible directly/indirectly now?

Thanks for any opinions and suggestion!

like image 664
abisheksampath Avatar asked Jun 08 '26 08:06

abisheksampath


2 Answers

@SpringBootApplication(
    exclude = { 
        CompositeMeterRegistryAutoConfiguration.class,
        DataSourcePoolMetricsAutoConfiguration.class, 
        TomcatMetricsAutoConfiguration.class,
        SimpleMetricsExportAutoConfiguration.class, 
        SystemMetricsAutoConfiguration.class 
    }
)

You need to exclude all the metrics auto configuration classes which are responsible for the default metrics in Spring Boot.

You can find all the metrics auto configuration classes here:

https://github.com/spring-projects/spring-boot/blob/v2.1.1.RELEASE/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories

like image 144
samar ranjan Nayak Avatar answered Jun 11 '26 00:06

samar ranjan Nayak


Like most things in Spring Boot, the default metrics are configured via various auto-configuration classes. To disable the default metrics, exclude their auto-configuration classes using the exclude attribute on @SpringBootApplication. To see what auto-configurations are involved, you can launch your app with --debug or take a look at the source code.

like image 31
Andy Wilkinson Avatar answered Jun 11 '26 01:06

Andy Wilkinson