6
votes

Cannot include Prometheus metrics in spring boot 2 (version 2.0.0.M7) project.

According micrometer docs added spring-boot-starter-actuator dependency and in application.yaml added management.endpoints.web.expose: prometheus but when calling /actuator/prometheus get
{ "timestamp": 1518159066052, "path": "/actuator/prometheus", "message": "Response status 404 with reason \"No matching handler\"", "status": 404, "error": "Not Found" }

Tell me please why I wasn't getting prometheus metrics?

3

3 Answers

6
votes

Did you add micrometer-registry-prometheus to your dependecies?

Micrometer has a pluggable architecture where you need to define (by plugging dependencies) what monitoring system you'd like to work with. (You can even add multiple, not just one.)

Btw, you should be switching to Spring Boot 2.0.0.RC1. That's the current one as of this writing.

10
votes

I had trouble initiating micrometer with Springboot 2. x.

These changes in my project helped me to expose the metrics atactuator/prometheus endpoint

These are the changes in my application.properties file

management.endpoints.web.exposure.include=*
management.endpoint.metrics.enabled=true

My build.gradle file included

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')
8
votes

Edit: Since I gave this answer a lot has changed. It was valid for 2.0.0.RC1. Please read the documentation https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html

If above solution doesn't work for someone try this: I had the same issue with Spring Boot 2.0.0.RC1, spring-boot-starter-web and of course spring-boot-starter-actuator.

My application.properties file read:

management.endpoints.web.expose=prometheus,metrics,info,health

In my pom file I had additionally:

    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient</artifactId>
        <version>0.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <version>0.12.0.RELEASE</version>
    </dependency>

Prometheus metrics under /actuator/prometheus where only shown after I had switched to the newest version of micrometer-registry-prometheus:

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <version>1.0.0-rc.9</version>
    </dependency>