Search code examples
spring-bootmicrometerstatsd

Spring boot micrometer ignores management.metrics.export.statsd.host setting


I am trying to add StatsD metrics to a Spring boot application using Micrometer.

It works locally, but fails in production, logging errors saying that its unable to connect to localhost:8125 despite having management.metrics.export.statsd.host configured correctly.

I added an endpoint to the service that returns the value of the management.metrics.export.statsd.host application property, and it returns the value I configured, so this part seems to be good, but for some reason the management.metrics.export.statsd.host application property is ignored by micrometer.

I added StatsD metrics reporting to my app by adding this to the pom.xml file:

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-statsd</artifactId>
            <version>1.13.1</version>
        </dependency>

And adding this to the application.properties file:

management.metrics.export.statsd.enabled=true
management.metrics.export.statsd.host=deliberately_broken
management.metrics.export.statsd.port=8125

On my local machine it successfully outputs metrics to localhost in spite of having deliberately_broken as the configured host name, and on production it also tries to send metrics to localhost even though this application property is set correctly.


Solution

  • According to the official docs, the property you should use for Spring Boot 3.x is management.statsd.metrics.export.host.

    The property was management.metrics.export.statsd.host previously in Spring Boot 2.x which is no longer supported.

    Since it is a Boot property, it should be found in the official Boot docs, see: management.statsd.metrics.export.host