Search code examples
spring-bootmicrometerspring-micrometer

How to configure Micrometer's monitoring system at runtime with Spring Boot


I'm new to metrics in general and especially Micrometer, so this might be a dumb question:

Micrometer describes itself on the home page as a "facade" "without vendor lock-in", "think SLF4J, but for metrics". With "built-in support for [...] Netflix Atlas". The docs say it's included in Spring Boot 2.

So what I'd expect is the ability to configure the monitoring system on start-up - just as I would with SLF4J. So this doc describes a setting management.metrics.export.atlas.enabled (among others) for Spring Boot. But even with this setting auto-wiring a MeterRegistry registry fails as follows:

Parameter 4 of constructor in [snip] required a bean of type 'io.micrometer.core.instrument.MeterRegistry' that could not be found.

Action:

Consider defining a bean of type 'io.micrometer.core.instrument.MeterRegistry' in your configuration.

Google led me to Baeldung where I read about some micrometer-registry-atlas dependency plus providing a MeterRegistrybean of type AtlasMeterRegistry. This works, but it's not what I call a "facade without vendor lock-in", but I guess I'm just doing it wrong?

How can I provide the monitoring system during runtime, switching between Atlas and any other without re-compiling?


Solution

  • @crusy you are actually right, but the feature is part of the Actuator module. This is not well documented and I was lucky to find the answer in the Spring Boot Gitter channnel https://gitter.im/spring-projects/spring-boot/archives/2019/01/24?at=5c4980b00721b912a5cdc02f.

    You will notice that the Metrics section in the Spring Boot documentation is under Actuator: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-metrics.

    This means that in order for Micrometer to work out of the box, you need to include Actuator in your build. E.g for Gradle:

    implementation ('org.springframework.boot:spring-boot-starter-actuator')
    

    The MeterRegistry bean will be there now.