Spring Boot Actuator
FROM:https://springdoc.cn/spring-boot/actuator.html#actuator
健康信息:https://springdoc.cn/spring-boot/actuator.html#actuator.endpoints.health
K8s探针(springboot 2.3.3及以上版本):https://springdoc.cn/spring-boot/actuator.html#actuator.endpoints.kubernetes-probes
健康信息:
在 Spring Boot Actuator 中,/actuator/health 端点返回一个表示应用健康状况的对象,其中 status 字段是核心部分,它表示整个应用或各个组件的整体健康状态。status 的可能值包括但不限于:
UP: 表示应用及所有检查的组件均处于正常运行状态。DOWN: 表示应用或至少有一个组件存在问题,无法正常运行。当任何内置或自定义的 Health Indicator 报告状态为DOWN时,整体status也将变为DOWN。OUT_OF_SERVICE: 表示应用的某个组件已主动标记为维护模式或暂时不可用。UNKNOWN: 表示由于某种原因,健康状况无法确定。
响应体还可能包含更详细的 components 部分,显示各个单独组件的健康状态和详细信息。
例如:
json
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 250182889472,
"free": 31169568768,
"threshold": 10485760
}
},
"db": {
"status": "UP",
"details": {
"database": "MySQL",
"helloWorld": 1
}
}
}
}
在上面的示例中,整个应用的 status 为 UP,因为所有列出的组件(如磁盘空间 diskSpace 和数据库 db)也都处于 UP 状态。如果 db 组件出现问题导致其 status 变为 DOWN,则整个应用的 status 也将随之变更为 DOWN。
| Health Status | Response Status |
|---|---|
| DOWN | 503(Service Unavailable) |
| OUT_OF_SERVICE | 503(Service Unavailable) |
| UP | 200(OK) |
| UNKNOWN |
健康信息详情展示级别:
| 值 | 说明 |
|---|---|
| never | 细节从不显示。 |
| when-authorized | 细节只显示给授权用户。 授权的角色可以通过使用 management.endpoint.health.roles 进行配置。 |
| always | 详情显示给所有用户。 |
health端点 自动配置的HealthIndicators
| Key | Name | 说明 |
|---|---|---|
| cassandra | CassandraDriverHealthIndicator | 检查Cassandra数据库是否已经启动。 |
| couchbase | CouchbaseHealthIndicator | 检查Couchbase集群是否已经启动。 |
| db | DataSourceHealthIndicator | 检查是否可以获得与DataSource的连接。 |
| diskspace | DiskSpaceHealthIndicator | 检查磁盘空间是否不足。 |
| elasticsearch | ElasticsearchRestHealthIndicator | 检查Elasticsearch集群是否已经启动。 |
| hazelcast | HazelcastHealthIndicator | 检查Hazelcast服务器是否已经启动。 |
| influxdb | InfluxDbHealthIndicator | 检查InfluxDB服务器是否已经启动。 |
| jms | JmsHealthIndicator | 检查一个JMS代理是否已经启动。 |
| ldap | LdapHealthIndicator | 检查一个LDAP服务器是否正常。 |
| MailHealthIndicator | 检查一个邮件服务器是否正常。 | |
| mongo | MongoHealthIndicator | 检查Mongo数据库是否已经启动。 |
| neo4j | Neo4jHealthIndicator | 检查Neo4j数据库是否已经启动。 |
| ping | PingHealthIndicator | 总是响应 UP 。 |
| rabbit | RabbitHealthIndicator | 检查一个Rabbit服务器是否已经启动。 |
| redis | RedisHealthIndicator | 检查Redis服务器是否已经启动。 |
在适当的时候,Spring Boot会自动配置下表中列出的 HealthIndicators。 你也可以通过配置 management.health.key.enabled 来启用或停用所选指标。
你可以通过设置 management.health.defaults.enabled 属性来禁用它们。
额外的 HealthIndicators 是可用的,但在默认情况下不启用(springboot 2.3.3及以上版本可用)。
| Key | Name | 说明 |
|---|---|---|
| livenessstate | LivenessStateHealthIndicator | 显示 "Liveness" 应用程序的可用性状态。 |
| readinessstate | ReadinessStateHealthIndicator | 暴露 "Readiness" 应用程序的可用性状态。 |