spring - Spring Boot 2 迁移后未导出 Health Endpoint Metrics
问题描述
我的团队将我们的微服务从 Spring Boot 1 迁移到了版本 2,并且由于执行器发生了变化,我们通过 prometheus jmx 导出器导出的 Health Endpoint Metrics 不再起作用。
通常的 /actuator/health 按预期工作,但prometheus-jmx-exporter不会拿起它,尽管尝试了几件事:
- 我更改了 exporter-config.yaml 中的元信息以反映 Spring Boot 2 中的名称更改
- 我将 io.micrometer:micrometer-registry-prometheus 添加到我们的 build.gradle 中,看看这是否是问题所在
- 我根据 Spring Boot 2 文档公开了 web 和 jmx 端点
所以现在我的想法已经用完了,如果oyu能给我任何提示,我将不胜感激
旧的 prometheus-jmx-exporter exporter-config.yaml:
---
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.springframework.boot:type=Endpoint,name=healthEndpoint"]
rules:
- pattern: 'org.springframework.boot<type=Endpoint, name=healthEndpoint><(.*, )?(.*)>(.*):'
name: health_endpoint_$1$3
attrNameSnakeCase: true
新的 prometheus-jmx-exporter exporter-config.yaml:
---
lowercaseOutputName: true
lowercaseOutputLabelNames: true
whitelistObjectNames: ["org.springframework.boot:type=Endpoint,name=Health"]
rules:
- pattern: 'org.springframework.boot<type=Endpoint, name=Health>'
name: health_endpoint_$1$3
attrNameSnakeCase: true
当前关于执行器端点的应用程序属性:
management.endpoints.web.exposure.include=info, health, refresh, metrics, prometheus
management.endpoints.jmx.exposure.include=health, metrics, prometheus
在带有旧 exporter-config.yaml 的 Spring Boot 1 中,我得到如下结果:
# HELP health_endpoint_hystrix_status Invoke the underlying endpoint (org.springframework.boot<type=Endpoint, name=healthEndpoint><hystrix, status>status)
# TYPE health_endpoint_hystrix_status untyped
health_endpoint_hystrix_status 1.0
# HELP health_endpoint_status Invoke the underlying endpoint (org.springframework.boot<type=Endpoint, name=healthEndpoint><status>status)
# TYPE health_endpoint_status untyped
health_endpoint_status 1.0
但是随着所有的变化和 Spring Boot 2 中的变化,我什么也没得到。
解决方案
您可以配置自己的健康值并将其添加到 Prometheus Metrics 端点:
@Configuration
public class HealthMetricsConfiguration {
@Bean
public MeterRegistryCustomizer prometheusHealthCheck(HealthEndpoint healthEndpoint) {
return registry -> registry.gauge("health", healthEndpoint, HealthMetricsConfiguration::healthToCode);
}
public static int healthToCode(HealthEndpoint ep) {
Status status = ep.health().getStatus();
return status.equals(Status.UP) ? 1 : 0;
}
}
推荐阅读
- mysql - Nods.js 路由器抛出“语法错误:等待仅在异步函数中有效”
- python - 返回部分匹配的正则表达式
- javascript - 如何在不同的 ngRoute 页面中使用相同的控制器
- python - 无法在 Linux mint 19.1 上为 python3.7.4 安装 Django 2.2.4
- javascript - 有没有办法用 youtube 视频填充 div,比如 background-size:cover css 属性
- java - 我应该如何获取文档字段并将它们用于另一个地图的另一个集合?
- ruby-on-rails - 如何在一张幻灯片中显示两张图片
- android - 如何在房间数据库中添加主键?
- java - 错误部分 setContentView(binding.getRoot());
- python - 确定确切路径,包括 Flask + gevent.pywsgi WSGIServer 服务器上是否存在尾随问号