'Spring Boot Actuator/Micrometer Metrics Disable Some
Is there a way to turn off some of the returned metric values in Actuator/Micrometer? Looking at them now I'm seeing around 1000 and would like to whittle them down to a select few say 100 to actually be sent to our registry.
Solution 1:[1]
Let me elaborate on the answer posted by checketts with a few examples. You can enable/disable certain metrics in your application.yml like this:
management:
metrics:
enable:
tomcat: true
jvm: false
process: false
hikaricp: false
system: false
jdbc: false
http: false
logback: true
Or in code by defining a MeterFilter bean:
@Bean
public MeterFilter meterFilter() {
return new MeterFilter() {
@Override
public MeterFilterReply accept(Meter.Id id) {
if(id.getName().startsWith("tomcat.")) {
return MeterFilterReply.DENY;
}
if(id.getName().startsWith("jvm.")) {
return MeterFilterReply.DENY;
}
if(id.getName().startsWith("process.")) {
return MeterFilterReply.DENY;
}
if(id.getName().startsWith("system.")) {
return MeterFilterReply.DENY;
}
return MeterFilterReply.NEUTRAL;
}
};
}
Solution 2:[2]
The property naming in Mzzl's answer has changed in Spring Boot 2. For example, to disable the JVM metrics it's now:
management.metrics.binders.jvm.enabled=false
See this class for the other options. The Spring team have refactored yet again in 2.1.x and those inner factory bean classes are now lifted out into standalone files but the property naming remains the same as 2.0.x.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | schemacs |
| Solution 2 | Andy Brown |
