https://gitee.com/DanShenGuiZu/learnDemo/tree/master/actuator-learn/actuator01
http://127.0.0.1:8080/actuator/health

status的值有2个
1. {“status”:“UP”}
2. {“status”:“DOWN”}
# 查看详细的应用健康信息
# never:不展示详细信息,up或者down的状态,默认配置
# when-authorized:详细信息将会展示给通过认证的用户。授权的角色可以通过management.endpoint.health.roles配置
# 对所有用户暴露详细信息
management.endpoint.health.show-details=always

http://127.0.0.1:8080/actuator/health

从上面的应用的详细健康信息发现,健康信息包含磁盘空间、网络。
如果我们有配置redis,mysql,那么返回的信息就会有对应redis和mysql的信息,因为actuator会自动给监控起来。

当如上的组件有一个状态异常,应用服务的整体状态即为down。我们也可以通过配置禁用健康监测。
# 禁用mongodb组件
management.health.mongo.enabled: false
# 禁用所有自动配置的健康指示器
management.health.defaults.enabled: false
org.springframework.boot.actuate.health.OrderedHealthAggregator。

# 禁用某个(xxxx) HealthIndicators
management.health.xxxx.enabled: false
# 禁用所有自动配置的健康指示器
management.health.defaults.enabled: false
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MYHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// 执行一些特定的监控检查
int errorCode = check();
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
// 执行一些特定的监控检查
private int check() {
return 0;
}
}


除了Spring boot定义的几个状态类型,我们也可以自定义状态类型,用来表示一个新的系统状态。
在这种情况下,你还需要实现接口 HealthAggregator ,或者通过配置 management.health.status.order 来继续使用HealthAggregator的默认实现。
在你自定义的健康检查实现类 MYHealthIndicator中,使用了自定义的状态类型FATAL,为了配置该状态类型的严重程度,你需要在application的配置文件中添加如下配置:
management.health.status.order=FATAL, DOWN, OUT_OF_SERVICE, UNKNOWN, UP
在做健康检查时,响应中的HTTP状态码反应了整体的健康状态,(例如,UP 对应200, 而 OUT_OF_SERVICE 和 DOWN 对应 503)。
同样,你也需要为自定义的状态类型设置对应的HTTP状态码,例如,下面的配置可以将 FATAL 映射为 503(服务不可用):
management.health.status.http-mapping.FATAL=503

自定义自己的 HealthStatusHttpMapper bean。
