Spring Boot Actuator/Micrometer Metrics Disable Some

Joel Holmes picture Joel Holmes · Jan 25, 2018 · Viewed 8.8k times · Source

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.

Answer

Mzzl picture Mzzl · Jan 8, 2019

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;
        }
    };
}