我想展示使用千分尺普罗米修斯与 spring-boot-actuator 结合使用的一些指标。我的项目完全基于 spring-boot 并启用了执行器功能并映射到以下网址:http://localhost:9000/actuator 其他端点显示正确,但 http://localhost:9000/actuator/prometheus 未正确显示。下面是我访问此 http 端点时获得的屏幕截图。
有人可以帮助我吗?为什么会发生这种情况以及如何解决它? 因为当您提供合适的依赖项时,普罗米修斯通常会自动为 spring-boot-actuator 配置。
您需要检查很多事情才能确保通过 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
注意:您必须检查编写脚本的位置,因为我对 endpoint 和 endpoints
感到困惑注意:您可以从
application.yml
中删除端口,执行器将通过当前应用程序端口运行
祝你好运
默认情况下这是自动配置的,以下是一些故障排除指南:
micrometer-registry-prometheus
(没有定义版本,版本应该来自BOM)management.endpoints.web.exposure.include=*
/
,/actuator
,/actuator/prometheus
)curl localhost:9090/actuator/prometheus
对我来说,这成功了,启用了其他所有内容(端点和指标),但没有这个, /actuactor/prometheus 就不会暴露
management:
metrics:
export:
prometheus:
enabled: true
非常感谢。 我用bean PrometheusMeterRegistry初始化注释掉了代码,最后我在/actuator/prometheus中观察结果。
好的,我用解决方案解决了它:
我手动创建了一个 prometheusMeterRegistry 类型的 bean,因此 spring boot 没有自动配置它,导致 prometheus 端点没有提供任何指标 有关更多详细信息,请参阅下面的代码片段:
// @Bean
// public PrometheusMeterRegistry prometheusMeterRegistry() {
// return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// }
就我而言,我试图在旧项目上设置普罗米修斯,其中
MetricsAutoConfiguration
被排除在外。所以删除排除解决了问题。
@EnableAutoConfiguration(exclude = { MetricsAutoConfiguration.class})