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.
Meter filters can help in 3 ways that have been discussed with the Micrometer slack channel:
- Disabling metrics
- Combining dimensions
- High cardinality capping filter
Micrometer comes with the first type of meter filter built in. It also support hierarchical enabling/disabling similar to how logging works (As in if have meter like my.request.total
and my.request.latency
you can disable all metrics that start with my.request
.
I've implemented my own example of a combining filter which is useful if you have a metrics with high cardinality and want to combine them in new dimmensions. Take for example you have a dimension on status codes, this lets you combine 200, 201, 203 response codes as a tag 2xx
. This is similar to Netflix Spectator 'placeholder' support. I would love to contribute that code upstream, but currently it is pretty custom, so it would need some work to make it generally usable.
The last type for catching high cardinality dimensions, hasn't been created yet, but would exist as a safety valve ensuring that if a metric can potentially have a high number of tag value, it will count the number of unique tags and once a max value is hit, either disable or combine the additional tags into a common bucket, so that value doesn't explode and potentially overwhel your monitoring (or cost you lots of $$$, if paying per-metric)
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
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;
}
};
}
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
.
来源:https://stackoverflow.com/questions/48451381/spring-boot-actuator-micrometer-metrics-disable-some