欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > Spring Boot Actuator 健康信息

Spring Boot Actuator 健康信息

2026/4/20 22:54:53 来源:https://blog.csdn.net/qq_40728339/article/details/148608344  浏览:    关键词:Spring Boot Actuator 健康信息

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 部分,显示各个单独组件的健康状态和详细信息。

例如:

{"status": "UP","components": {"diskSpace": {"status": "UP","details": {"total": 250182889472,"free": 31169568768,"threshold": 10485760}},"db": {"status": "UP","details": {"database": "MySQL","helloWorld": 1}}}
}

在上面的示例中,整个应用的 statusUP,因为所有列出的组件(如磁盘空间 diskSpace 和数据库 db)也都处于 UP 状态。如果 db 组件出现问题导致其 status 变为 DOWN,则整个应用的 status 也将随之变更为 DOWN

Health StatusResponse Status
DOWN503(Service Unavailable)
OUT_OF_SERVICE503(Service Unavailable)
UP200(OK)
UNKNOWN

健康信息详情展示级别:

说明
never细节从不显示。
when-authorized细节只显示给授权用户。 授权的角色可以通过使用 management.endpoint.health.roles 进行配置。
always详情显示给所有用户。

health端点 自动配置的HealthIndicators

KeyName说明
cassandraCassandraDriverHealthIndicator检查Cassandra数据库是否已经启动。
couchbaseCouchbaseHealthIndicator检查Couchbase集群是否已经启动。
dbDataSourceHealthIndicator检查是否可以获得与DataSource的连接。
diskspaceDiskSpaceHealthIndicator检查磁盘空间是否不足。
elasticsearchElasticsearchRestHealthIndicator检查Elasticsearch集群是否已经启动。
hazelcastHazelcastHealthIndicator检查Hazelcast服务器是否已经启动。
influxdbInfluxDbHealthIndicator检查InfluxDB服务器是否已经启动。
jmsJmsHealthIndicator检查一个JMS代理是否已经启动。
ldapLdapHealthIndicator检查一个LDAP服务器是否正常。
mailMailHealthIndicator检查一个邮件服务器是否正常。
mongoMongoHealthIndicator检查Mongo数据库是否已经启动。
neo4jNeo4jHealthIndicator检查Neo4j数据库是否已经启动。
pingPingHealthIndicator总是响应 UP 。
rabbitRabbitHealthIndicator检查一个Rabbit服务器是否已经启动。
redisRedisHealthIndicator检查Redis服务器是否已经启动。

在适当的时候,Spring Boot会自动配置下表中列出的 HealthIndicators。 你也可以通过配置 management.health.key.enabled 来启用或停用所选指标。

你可以通过设置 management.health.defaults.enabled 属性来禁用它们。

额外的 HealthIndicators 是可用的,但在默认情况下不启用(springboot 2.3.3及以上版本可用)。

KeyName说明
livenessstateLivenessStateHealthIndicator显示 “Liveness” 应用程序的可用性状态。
readinessstateReadinessStateHealthIndicator暴露 “Readiness” 应用程序的可用性状态。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词