I have a Spring boot application where I am sending custom metrics generated within the service to Prometheus via Pushgateway.
I am using Prometheus Pushgateway with Micrometer, mainly based on this tutorial: https://luramarchanjo.tech/2020/01/05/spring-boot-2.2-and-prometheus-pushgateway-with-micrometer.html
I have following dependencies in my pom.xml
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.16.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
And sending custom metrics with:
Counter counter = Counter.builder("sb_console_test_counter").register(meterRegistry);
counter.increment();
It is working fine and I can view the custom metrics generated by the application however in addition to this I am seeing application specific metrics generated by Spring boot e.g.
tomcat_sessions_active_current_sessions tomcat_sessions_active_max_sessions
etc.
I only want to capture the custom metrics generated by my code and not any other generic metrics, how can I stop sending this?
CodePudding user response:
When you add the dependency spring-boot-starter-actuator
you will get a lot of metrics out of the box from various configurations such as JvmMetricsAutoConfiguration
and TomcatMetricsAutoConfiguration
.
To filter those out, you could add a deny
filter in your Micrometer config, and only allow your custom metric meters to be registered.
Example using a deny filter:
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsRegistryConfig() {
return registry -> registry.config()
.meterFilter(MeterFilter.deny(id -> !id.getName().startsWith("sb_console")));
}
The above will deny any metrics not starting with sb_console
.
See this link for more info about the meter filters
CodePudding user response:
I believe you can just add this:
management.metrics.export.defaults.enabled=false
to your application.properties
. I see this in some of my code. I'm not set up to try it right now, but that's why we have it there.
If you want to add back some of the built in metrics, you can then add lines like this:
management.metrics.export.<groupname>.enabled=true