Spring Boot ⾃带的 Health Indicator
⽬的
- 检查应⽤程序的运⾏状态
状态
- DOWN - 503
- OUT_OF_SERVICE - 503
- UP - 200
- UNKNOWN - 200
机制
- 通过 HealthIndicatorRegistry 收集信息
- HealthIndicator 实现具体检查逻辑
配置项
- management.health.defaults.enabled=true|false
- management.health…enabled=true
- management.endpoint.health.show-details=never | whenauthorized | alway
⾃定义 Health Indicator
⽅法
- 实现 HealthIndicator 接⼝
- 根据⾃定义检查逻辑返回对应 Health 状态
-
- Health 中包含状态和详细描述信息
Health Information
官网地址:https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html#actuator.endpoints.health
可以使用运行状况信息(health information)检查正在运行的应用程序的状态。它经常被监控软件用于在生产系统崩溃时发出警报。health endpoint
公开的信息取决于management.endpoint.health.show-details
和management.endpoint.health.show-components
属性,可配置为以下值之一:
Name | Description |
---|---|
never | 从不显示详细信息。 |
when-authorized | 详细信息只显示给授权用户。可使用management.endpoint.health.roles 配置授权角色。 |
always | 详细信息将显示给所有用户。 |
缺省值为never
。当用户处于一个或多个endpoints的角色中时,就认为用户已获得授权。如果端点没有配置角色(默认),则所有经过身份验证的用户都被认为是经过授权的。可以使用management.endpoint.health.roles
属性配置角色。
如果已保护了应用程序并希望使用always
,则安全配置必须允许已验证和未验证的用户访问运行状况端点。
运行状况信息从HealthContributorRegistry
(默认情况下,ApplicationContext
中定义的所有HealthContributor
实例)的内容中收集。Spring Boot包括许多自动配置的