【问题标题】:Spring Boot 2.2.2 - Prometheus not working in ActuatorSpring Boot 2.2.2 - Prometheus 无法在 Actuator 中工作
【发布时间】:2019-12-18 12:54:49
【问题描述】:

我已将我的 Spring Boot 应用程序升级到最新的 2.2.2 Boot 版本。从那以后,我只有一个指标端点,但没有 Prometheus。

我的 build.gradle.kts 文件具有 org.springframework.boot:spring-boot-starter-actuator 作为依赖项,我还添加了 io.micrometer:micrometer-registry-prometheus 作为参考建议 (Prometheus endpoint)。

我的 application.yml 如下所示:

management:
  server:
    port: 9000
  endpoints:
    web:
      exposure:
        include: health, shutdown, prometheus
  endpoint:
    shutdown:
      enabled: true

谁能指引我正确的方向?

编辑:它在 Spring Boot 2.2.0 中工作。这是下载相同项目的链接:link

编辑 2:我可以验证它是否也适用于 2.2.1。

【问题讨论】:

  • 嗯,这很奇怪。我有相同的设置,它工作得很好。
  • @jirka.pinkas 你确定吗?我刚刚又下载了一个新项目,结果一样:start.spring.io/… 并添加implementation("io.micrometer:micrometer-registry-prometheus")
  • 只有两个区别:1. 我使用 Maven,2. 我的 application.properties 中有:management.endpoints.web.exposure.include=* 我的依赖项:actuator & micrometer-registry-prometheus & spring-boot-starter-web。编辑:刚刚用新项目(在start.spring.io上创建)对其进行了测试,它可以工作。 EDIT2:即使使用 management.endpoints.web.exposure.include=health,shutdown,prometheus 它也可以工作
  • 也许发现了你的问题:你使用的是 webflux,而不是 web。似乎它不适用于 webflux(目前):stackoverflow.com/questions/48603285/…
  • @jirka.pinkas 它应该可以工作,我一直在将它与 WebFlux + Spring Boot 2.2.0 一起使用,没有任何问题。 :(

标签: spring-boot prometheus spring-boot-actuator


【解决方案1】:

我按照你的设置,从this project loaded创建了一个项目Spring Boot 2.2.2.RELEASE,我为Prometheus添加了以下依赖项

implementation("io.micrometer:micrometer-registry-prometheus")

另外我在application.yml中添加了如下配置

management:
  server:
    port: 9000
  endpoints:
    web:
      exposure:
        include: health, shutdown, prometheus
  endpoint:
    shutdown:
      enabled: true

当应用程序启动时,您将看到以下信息,显示 3 个端点已暴露(健康、关闭和普罗米修斯)

2020-01-05 23:48:19.489  INFO 7700 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 3 endpoint(s) beneath base path '/actuator'

并将Postman 用于方法GET 这个端点http://localhost:9000/actuator/prometheus 并且效果很好。我按照这些步骤创建了一个存储库here 所以请告诉我显示了什么错误,或者当你没有得到预期结果时会发生什么,以便我可以帮助和编辑这个答案。

【讨论】:

  • 感谢您的澄清!那么这显然是我这边的事情。
  • 嗨乔纳森。我使用 sprint boot 2.2.6 执行相同的步骤,但我得到以下信息:2020-04-14 15:28:02.159 INFO 81411 --- [main] o.s.b.a.e.web.EndpointLinksResolver:在基本路径下暴露 2 个端点' /actuator' 你知道为什么吗?
  • @ShalomBalulu 你也有include: health, shutdown, prometheus 对吗?请使用您所指内容的版本打开一个新问题,以便我可以帮助您...
  • 添加对 io.micrometer:micrometer-registry-prometheus 的依赖对我有用。在阅读 Spring Boot 文档时,这对我来说并不明显。
  • @MichaelChristensen 很好,如果您对 Spring Boot 有任何疑问,可以关注我的个人资料,然后发送邮件,问候。
【解决方案2】:

为prometheus添加下面的maven依赖

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <scope>runtime</scope>
</dependency>

在application.yml中,添加如下配置

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-components: always
      show-details: always
      probes:
        enabled: true

现在你可以在重新启动服务器时看到以下消息

Exposing 15 endpoint(s) beneath base path '/actuator'

访问prometheus url:http://localhost:8080/actuator/prometheus

【讨论】:

    猜你喜欢
    • 2021-05-30
    • 2020-06-01
    • 2016-06-01
    • 2022-01-06
    • 1970-01-01
    • 2021-04-23
    • 2020-09-15
    • 2021-06-16
    • 2021-09-11
    相关资源
    最近更新 更多