跳到主要内容

健康 (health)

DeepSeek V3 中英对照 Health (health)

health 端点提供了关于应用程序健康状况的详细信息。

获取应用程序的健康状态

要获取应用程序的健康状态,可以向 /actuator/health 发送一个 GET 请求,如下面基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/health' -i -X GET \
-H 'Accept: application/json'
bash

生成的响应类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 821

{
"status" : "UP",
"components" : {
"broker" : {
"status" : "UP",
"components" : {
"us1" : {
"status" : "UP",
"details" : {
"version" : "1.0.2"
}
},
"us2" : {
"status" : "UP",
"details" : {
"version" : "1.0.4"
}
}
}
},
"db" : {
"status" : "UP",
"details" : {
"database" : "H2",
"validationQuery" : "isValid()"
}
},
"diskSpace" : {
"status" : "UP",
"details" : {
"total" : 76887154688,
"free" : 50716430336,
"threshold" : 10485760,
"path" : "/home/runner/work/spring-boot/spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/.",
"exists" : true
}
}
}
}
http

响应结构

响应包含应用程序的健康状态详细信息。下表描述了响应的结构:

路径类型描述
statusString应用程序的整体状态。
componentsObject构成健康状况的组件。
components.*.statusString应用程序特定部分的状态。
components.*.componentsObject构成健康状况的嵌套组件。
components.*.detailsObject应用程序特定部分的健康状况详情。其存在由 management.endpoint.health.show-details 控制。
备注

上方的响应字段适用于 V3 API。如果需要返回 V2 JSON,您应该使用 accept 头或 application/vnd.spring-boot.actuator.v2+json

获取组件的健康状况

要检索应用程序健康中某个特定组件的健康状况,请向 /actuator/health/{component} 发起 GET 请求,如下所示基于 curl 的示例:

$ curl 'http://localhost:8080/actuator/health/db' -i -X GET \
-H 'Accept: application/json'
bash

生成的响应类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 101

{
"status" : "UP",
"details" : {
"database" : "H2",
"validationQuery" : "isValid()"
}
}
http

响应结构

响应内容包含了应用程序健康状态中某个特定组件的健康详情。下表描述了响应的结构:

路径类型描述
statusString应用程序某一部分的状态
detailsObject应用程序某一部分的健康状况详情。

获取嵌套组件的健康状态

如果某个组件包含其他嵌套组件(如上述示例中的 broker 指标),可以通过向 /actuator/health/{component}/{subcomponent} 发送 GET 请求来检索此类嵌套组件的健康状况,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/health/broker/us1' -i -X GET \
-H 'Accept: application/json'
bash

生成的响应类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 66

{
"status" : "UP",
"details" : {
"version" : "1.0.2"
}
}
http

应用程序健康状态的组成部分可能会根据应用程序的健康指标及其分组方式而任意深度地嵌套。健康端点支持在 URL 中使用任意数量的 /{component} 标识符,以便检索任意深度组件的健康状态。

响应结构

响应包含应用程序特定组件实例的健康状态详情。下表描述了响应的结构:

路径类型描述
statusString应用程序特定部分的状态
detailsObject应用程序特定部分的健康状态详情。