Spring Boot 2.2.2 - Prometheus 在 Actuator 中不工作

Spring Boot 2.2.2 - Prometheus not working in Actuator

我已经将 Spring 引导应用程序升级到最新的 2.2.2 引导版本。从那时起,我只有一个指标端点而没有 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 下载相同的项目:link

编辑 2:我可以验证它也适用于 2.2.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 所以请让我知道显示了什么错误,或者当您没有得到预期结果时会发生什么,以便我可以帮助和编辑这个答案。

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

访问普罗米修斯url:http://localhost:8080/actuator/prometheus