Spring Boot health 端点的默认配置有什么用
How is the default configuration of the Spring Boot health endpoint useful
Spring Boot可以提供一个health endpoint. That is an HTTP URI (/actuator/health
, by default) you can GET for health information关于应用程序。 Spring Boot 默认启用此功能。 Spring Boot 还有一个配置属性,management.endpoint.health.show-details
,用于确保响应中是否包含详细信息。 属性 的默认值为 never
,因此未显示详细信息。因此 Spring Boot 的默认配置是提供端点,但没有任何细节。
但是没有细节的健康端点有什么用呢?尽管资源不包含详细信息,但能够获取资源告诉您什么?
如果您使用 management.endpoint.health.show-details=never
,您仍然可以看到聚合状态。此状态是所有详细状态的聚合。默认情况下,使用 OrderedHealthAggregator
,这导致:
- 如果所有详细信息都是
UP
,父项也是 UP
- 如果其中一个细节是
DOWN
,父级也是DOWN
这是the documentation的相关部分:
By default, the final system state is derived by the HealthAggregator
which sorts the statuses from each HealthIndicator
based on an ordered list of statuses. The first status in the sorted list is used as the overall health status. If no HealthIndicator
returns a status that is known to the HealthAggregator
, an UNKNOWN
status is used.
顺序可以通过management.health.status.order
属性配置。默认情况下它包含 DOWN, OUT_OF_SERVICE, UNKNOWN, UP
.
HTTP 状态也会根据聚合状态发生变化。 UP
和 UNKNOWN
都会导致 HTTP 状态 200,而 DOWN
和 OUT_OF_SERVICE
会导致 HTTP 状态 503。这是 the documentation 的相关部分:
The HTTP status code in the response reflects the overall health status (for example, UP
maps to 200, while OUT_OF_SERVICE
and DOWN
map to 503).
您还可以配置应选择哪个 HTTP 状态,例如配置 management.health.status.http-mapping.DOWN=418
。
这意味着您仍然可以使用该信息来了解是否有问题。这对于监控这些端点(Eureka、Kubernetes、任何监控工具……)的任何 tool/software 都是有用的。
您可能想知道,为什么不默认显示所有详细信息?好吧,问题是这可能包含敏感信息,例如您有多少磁盘 space,您的应用程序配置存储在哪里,您连接到什么类型的数据库,......
Spring Boot可以提供一个health endpoint. That is an HTTP URI (/actuator/health
, by default) you can GET for health information关于应用程序。 Spring Boot 默认启用此功能。 Spring Boot 还有一个配置属性,management.endpoint.health.show-details
,用于确保响应中是否包含详细信息。 属性 的默认值为 never
,因此未显示详细信息。因此 Spring Boot 的默认配置是提供端点,但没有任何细节。
但是没有细节的健康端点有什么用呢?尽管资源不包含详细信息,但能够获取资源告诉您什么?
如果您使用 management.endpoint.health.show-details=never
,您仍然可以看到聚合状态。此状态是所有详细状态的聚合。默认情况下,使用 OrderedHealthAggregator
,这导致:
- 如果所有详细信息都是
UP
,父项也是UP
- 如果其中一个细节是
DOWN
,父级也是DOWN
这是the documentation的相关部分:
By default, the final system state is derived by the
HealthAggregator
which sorts the statuses from eachHealthIndicator
based on an ordered list of statuses. The first status in the sorted list is used as the overall health status. If noHealthIndicator
returns a status that is known to theHealthAggregator
, anUNKNOWN
status is used.
顺序可以通过management.health.status.order
属性配置。默认情况下它包含 DOWN, OUT_OF_SERVICE, UNKNOWN, UP
.
HTTP 状态也会根据聚合状态发生变化。 UP
和 UNKNOWN
都会导致 HTTP 状态 200,而 DOWN
和 OUT_OF_SERVICE
会导致 HTTP 状态 503。这是 the documentation 的相关部分:
The HTTP status code in the response reflects the overall health status (for example,
UP
maps to 200, whileOUT_OF_SERVICE
andDOWN
map to 503).
您还可以配置应选择哪个 HTTP 状态,例如配置 management.health.status.http-mapping.DOWN=418
。
这意味着您仍然可以使用该信息来了解是否有问题。这对于监控这些端点(Eureka、Kubernetes、任何监控工具……)的任何 tool/software 都是有用的。
您可能想知道,为什么不默认显示所有详细信息?好吧,问题是这可能包含敏感信息,例如您有多少磁盘 space,您的应用程序配置存储在哪里,您连接到什么类型的数据库,......