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

我们两清 提交于 2019-12-10 10:17:54

问题


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?


回答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.




回答2:


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>



回答3:


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


来源:https://stackoverflow.com/questions/48700449/cannot-include-prometheus-metrics-in-spring-boot-2-version-2-0-0-m7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!