简体   繁体   English

在Spring Boot healtcheck状态更改时收到通知

[英]get notified when spring boot healtcheck status changes

Is there a way to get notified when the status of the registered health check indicators changes? 当注册的健康检查指标的状态发生变化时,有没有办法得到通知? For example, when the healthcheck indicator of database becomes down, I would like to take some actions. 例如,当数据库的运行状况检查指示灯熄灭时,我想采取一些措施。

Actually, my final goal is to export healthcheck status to Prometheus' metrics. 实际上,我的最终目标是将健康检查状态导出为Prometheus的指标。 So, when there is status change, I want to update health metrics. 因此,当状态发生变化时,我想更新运行状况指标。

I assume your question refers to Micrometer issue 416 and Micrometer-Docs issue 39 . 我假设您的问题涉及Micrometer 问题416和Micrometer-Docs 问题39

As per documentation, you can register the custom HealthMetricsConfiguration . 根据文档,您可以注册自定义HealthMetricsConfiguration The value of the gauge is determined by the status the ComposeHealthIndicator returns and is actually changing depending on the state of the single HealthIndicator s. 量规的值由ComposeHealthIndicator返回的状态确定,并且实际上根据单个HealthIndicator的状态而变化。

I am using afformentioned HealthMetricsConfiguration (just with different status value mappings as discussed in issue 416). 我使用的是提到的HealthMetricsConfiguration (就像问题416中讨论的那样,只是具有不同的状态值映射)。

Wen't ahead and implemented a custom alternating health indicator: Wen并没有实施自定义交替健康指标:

@Component
public class AlternatingHealthIndicator extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        int minute = LocalDateTime.now().getMinute();
        boolean minuteIsEven = minute % 2 == 0;
        builder.status(minuteIsEven ? Status.UP : Status.DOWN);
        builder.withDetail("description", "UP when current minute is even; DOWN when current minute is odd");
        builder.withDetail("currentMinute", minute);
        builder.withDetail("minuteIsEven", minuteIsEven);
    }

}

The health gauge exported on the Prometheus endpoint is minutely changing from 1=UP to -2=DOWN . 在Prometheus端点上导出的health指标正在从1=UP更改为-2=DOWN Here's a visualization: 这是一个可视化:

从Prometheus查询的Grafana中显示的交替健康状况

Regarding alerting, you can use Grafana alerting or look into Prometheus' Alertmanager. 关于警报,您可以使用Grafana警报或查看Prometheus的Alertmanager。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当使用 Spring 引导 Java 启动 SFTP 远程服务器时如何获得通知? - How to get notified when SFTP Remote Server is UP using Spring Boot Java? Spring Boot WebSocket - 如何在客户端订阅时获得通知 - Spring Boot WebSocket - how to get notified on client subscriptions Post 和 Get 未映射到 Spring Boot - 状态:404 - Post and Get not mapped to Spring boot - status : 404 当我们使用Rest模板在内部启动API时,如何在Spring Boot中获取API的HTTP状态 - How to get the HTTP status of an API in spring boot when we hit it internally using Rest template 如何获得有关加速度计更改的通知? - How can I get notified on accelerometer changes? 在 Spring Actuator 中禁用特定数据源的 HealtCheck - Disabling HealtCheck for specific DataSources in Spring Actuator 用户Wifi从一个网络更改为另一个网络时如何获得通知 - How to get notified when the users Wifi changes from one network to other 如何从 spring 启动 rest controller 获取状态描述 - How to get status description from spring boot rest controller 如何在 spring 启动应用程序状态之前运行wiremock? - How to get wiremock running before the spring boot application status up? 返回1xx状态代码时Spring Boot请求挂在那里 - Spring boot request hang there when return 1xx status code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM