Spring-Boot-Actuator 端点 Prometheus 未正确显示

问题描述 投票:0回答:6

我想展示使用千分尺普罗米修斯与 spring-boot-actuator 结合使用的一些指标。我的项目完全基于 spring-boot 并启用了执行器功能并映射到以下网址:http://localhost:9000/actuator 其他端点显示正确,但 http://localhost:9000/actuator/prometheus 未正确显示。下面是我访问此 http 端点时获得的屏幕截图。

有人可以帮助我吗?为什么会发生这种情况以及如何解决它? 因为当您提供合适的依赖项时,普罗米修斯通常会自动为 spring-boot-actuator 配置。

spring spring-boot prometheus spring-boot-actuator micrometer
6个回答
4
投票

您需要检查很多事情才能确保通过 Actuator 启用 Prometheus

  • 首先,您应该将以下依赖项放在您的

    pom.xml
    上,以便在您的项目中启用 Prometheus。

             <!-- enable prometheus-->
         <dependency>
             <groupId>io.micrometer</groupId>
             <artifactId>micrometer-registry-prometheus</artifactId>
             <version>1.10.2</version>
         </dependency>
    
  • 第二点你必须检查你的执行器是否存在 项目或不存在,如果不存在,则需要添加以下内容 依赖性。

         <!--to enable actuator help to trace project-->
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
    
  • 您需要将以下脚本添加到您的application.yml中以 启用执行器并通过执行器启用 Prometheus。

.

management:
  security:
    enabled: false
  server:
    port: 9000
  endpoint:
    metrics:
      enabled: true
    prometheus:
      enabled: true
    health:
      show-details: always
      show-components: always
      probes:
        enabled: true
    shutdown:
      enabled: true
    info:
      env:
        enabled: true
      enabled: true
  endpoints:
    web:
      exposure:
        include: prometheus, metrics, info, health, shutdown, beans

使用上述脚本,执行器将在端口 9000上运行,您可以向以下 URL 发送请求来访问执行器。

http://localhost:9000/actuator/prometheus

以及以下 URL 来访问 Prometheus

http://localhost:9000/actuator/prometheus

注意:您必须检查编写脚本的位置,因为我对 endpointendpoints

感到困惑
  • 用于设置执行器配置的端点
  • 设置执行器的 端点 URL 端点

注意:您可以从

 application.yml
中删除端口,执行器将通过当前应用程序端口运行

祝你好运


1
投票

默认情况下这是自动配置的,以下是一些故障排除指南:

  • 检查是否添加了
    micrometer-registry-prometheus
    (没有定义版本,版本应该来自BOM)
  • 检查执行器端点是否启用:
    management.endpoints.web.exposure.include=*
  • 检查是否有一个控制器映射了prometheus端点的路径或其任何子路径(
    /
    /actuator
    /actuator/prometheus
  • 检查您的浏览器是否欺骗了您
    curl localhost:9090/actuator/prometheus

0
投票

对我来说,这成功了,启用了其他所有内容(端点和指标),但没有这个, /actuactor/prometheus 就不会暴露

management:
  metrics: 
    export:
      prometheus:
        enabled: true



0
投票

非常感谢。 我用bean PrometheusMeterRegistry初始化注释掉了代码,最后我在/actuator/prometheus中观察结果。


-1
投票

好的,我用解决方案解决了它:

我手动创建了一个 prometheusMeterRegistry 类型的 bean,因此 spring boot 没有自动配置它,导致 prometheus 端点没有提供任何指标 有关更多详细信息,请参阅下面的代码片段:

// @Bean
// public PrometheusMeterRegistry prometheusMeterRegistry() {
//  return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// }

-1
投票

就我而言,我试图在旧项目上设置普罗米修斯,其中

MetricsAutoConfiguration
被排除在外。所以删除排除解决了问题。

@EnableAutoConfiguration(exclude = { MetricsAutoConfiguration.class})
© www.soinside.com 2019 - 2024. All rights reserved.