spring boot的健康检查HealthIndicators

想提供自定健康信息, 你可以注册实现HealthIndicator接口的Spring beans。 你需要提供一个health()方法的实现, 并返

回一个Health响应Health响应需要包含一个status和可的用于展示的情。

import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyHealth implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
} r
eturn Health.up().build();
}
}

除了Spring BootStatus型, Health也可以返回一个代表新的系的自定Status。 在种情况下, 需要提供
一个
HealthAggregator接口的自定义实现, 或使用management.health.status.order属性配置默实现
例如, 假
一个新的, 代码为FATALStatus被用于你的一个HealthIndicator实现中。 了配置重程度, 你需要将下面的配
置添加到
application属性文件中:
management.health.status.order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
如果使用HTTP访问health端点, 你可能想要注册自定status, 并使用HealthMvcEndpoint行映射。 例如, 你可以将
FATAL映射HttpStatus.SERVICE_UNAVAILABLE


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值