如何发布从 /actuator/health 到 /actuator/prometheus 的所有健康检查信息?

How can I publish all health check info from /actuator/health to /actuator/prometheus?

我想将 /actuator/health 上已有的所有信息发布到 /actuator/prometheus,因为 /actuator/prometheus 端点不包含有关磁盘 space 或 LDAP/database 可用性。我发现可以创建一个 DiskSpaceMetricsConfiguration class (https://www.ivankrizsan.se/2021/01/23/spring-boot-prometheus-disk-space-metrics),这很有效,但是 我不知道如何对应用程序状态、数据库状态和ldap 状态。

我正在使用 spring-boot 2.1.9、spring-boot-starter-actuator 2.5.1 和 micrometer-registry-prometheus 1.2.1。

您使用的版本不兼容,请使用Spring Boot BOM,它会为您设置版本。

Spring 引导文档中有一节是关于 Mapping Health Indicators to Micrometer Metrics 的。您可以对每个健康指标执行相同的操作。

这里的技巧是将健康指标转换为 Gauge,您可以通过多种方式执行此操作,这取决于您,您可以使用 0/1 值来指示服务是否 UP 或者你可以像上面的文档建议的那样为每个状态使用不同的值。