【问题标题】:Cannot include Prometheus metrics in spring boot 2 (version 2.0.0.M7)不能在 Spring Boot 2(版本 2.0.0.M7)中包含 Prometheus 指标
【发布时间】:2018-07-19 21:44:58
【问题描述】:

不能在 spring boot 2(版本 2.0.0.M7)项目中包含 Prometheus 指标。

根据micrometer docs 添加 spring-boot-starter-actuator 依赖并在 application.yaml 添加 ma​​nagement.endpoints.web.expose: prometheus 但在调用 /actuator/prometheus 获取
{ "timestamp": 1518159066052, "path": "/actuator/prometheus", "message": "Response status 404 with reason \"No matching handler\"", "status": 404, "error": "Not Found" }

请告诉我为什么我没有获得普罗米修斯指标?

【问题讨论】:

    标签: spring-boot metrics prometheus


    【解决方案1】:

    我在使用 Springboot 2.x 启动千分尺时遇到了问题。

    我项目中的这些更改帮助我在actuator/prometheus 端点公开指标

    这些是我的 application.properties 文件中的更改

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

    包含我的 build.gradle 文件

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

    【讨论】:

      【解决方案2】:

      编辑:自从我给出这个答案以来,发生了很多变化。它对 2.0.0.RC1 有效。请阅读文档https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html

      如果上述解决方案对某人不起作用,请尝试以下操作: 我对 Spring Boot 2.0.0.RC1、spring-boot-starter-web 和 spring-boot-starter-actuator 也有同样的问题。

      我的 application.properties 文件读取:

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

      在我的 pom 文件中我还有:

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

      /actuator/prometheus 下的 Prometheus 指标仅在我切换到最新版本的 micrometer-registry-prometheus 后显示:

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

      【讨论】:

      • 我认为属性 management.endpoints.web.expose 应该是 management.endpoints.web.exposure.include 与 Spring Boot 2.0.0.RELEASE,不是吗?同时还发布了micrometer-registry-prometheus,在撰写本文时为1.0.1
      • DerMiggel - 我认为你是对的。 @cholland 你能修改你的答案吗?我有一个错误的开始。
      【解决方案3】:

      您是否将micrometer-registry-prometheus 添加到您的依赖项中?

      Micrometer 具有可插入的架构,您需要在其中定义(通过插入依赖项)您想要使用的监控系统。 (您甚至可以添加多个,而不仅仅是一个。)

      顺便说一句,您应该切换到 Spring Boot 2.0.0.RC1。这是撰写本文时的当前版本。

      【讨论】:

      • 是的,我添加了 micrometer-registry-prometheus 依赖项,但它并没有解决我的问题。在文档中找到 endpoints.prometheus.id: micrometheus,但在 application.yaml 中我没有得到它。
      • @makson 您使用的是什么“网络”技术?当我使用spring-boot-starter-web 进行测试时,它可以使用2.0.0.M7 以及2.0.0.RC1。但是当我用spring-boot-starter-jersey 测试时,会吐出404。执行器端点未注册。您需要将 ResourceConfig Bean 添加/注册到您的上下文中,以便 JerseyAutoConfiguration 启动。
      • 我正在使用RouterFunctionsspring-boot-starter-webflux。将 spring 更新为2.0.0.RC1 后,所有工作。谢谢。
      猜你喜欢
      • 2018-06-17
      • 1970-01-01
      • 2021-11-30
      • 2020-03-26
      • 2018-06-20
      • 2018-06-29
      • 2018-05-17
      • 2021-04-23
      • 2019-08-09
      相关资源
      最近更新 更多