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

14,372

Solution 1

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.

Solution 2

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')

Solution 3

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>
Share:
14,372
makson
Author by

makson

Updated on June 23, 2022

Comments

  • makson
    makson almost 2 years

    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?

  • makson
    makson over 6 years
    yes, I added micrometer-registry-prometheus dependency, but it didn't solve my issue. In documentation found endpoints.prometheus.id: micrometheus, but in application.yaml I wasn't getting it.
  • mweirauch
    mweirauch over 6 years
    @makson What "web" technology are you using? When I test with spring-boot-starter-web it works with 2.0.0.M7 and also with 2.0.0.RC1. But when I test with spring-boot-starter-jersey a 404 is spit out. The actuator endpoints aren't registered. You need to add/register a ResourceConfig Bean to your context in order for the JerseyAutoConfiguration to kick in.
  • makson
    makson over 6 years
    I am using RouterFunctions and spring-boot-starter-webflux. After update spring to 2.0.0.RC1 all work. Thanks.
  • DerMiggel
    DerMiggel about 6 years
    I think the property management.endpoints.web.expose should instead be management.endpoints.web.exposure.include with Spring Boot 2.0.0.RELEASE, shouldn't it? And in the meantime there has also been a release of micrometer-registry-prometheus, at the time of writing it's 1.0.1.
  • Ashley Frieze
    Ashley Frieze almost 5 years
    DerMiggel - I think you're right. @cholland can you amend your answer? I had a false-start with it.