|
此版本仍在开发中,尚未被视为稳定版本。如需最新稳定版本,请使用 Spring Boot 4.0.4! |
健康状态 (health)
health 端点提供有关应用程序运行状况的详细信息。
检索应用程序的健康状态
要获取应用程序的健康状态,请向 /actuator/health 发送一个 GET 请求,如下所示的基于 curl 的示例:
$ curl 'http://localhost:8080/actuator/health' -i -X GET \
-H 'Accept: application/json'
生成的响应类似于以下内容:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 808
{
"components" : {
"broker" : {
"components" : {
"us1" : {
"details" : {
"version" : "1.0.2"
},
"status" : "UP"
},
"us2" : {
"details" : {
"version" : "1.0.4"
},
"status" : "UP"
}
},
"status" : "UP"
},
"db" : {
"details" : {
"database" : "H2",
"validationQuery" : "isValid()"
},
"status" : "UP"
},
"diskSpace" : {
"details" : {
"total" : 154894188544,
"free" : 119944216576,
"threshold" : 10485760,
"path" : "/home/runner/work/spring-boot/spring-boot/documentation/spring-boot-actuator-docs/.",
"exists" : true
},
"status" : "UP"
}
},
"status" : "UP"
}
响应结构
响应包含应用程序健康状况的详细信息。 下表描述了响应的结构:
| 路径 | 类型 | 描述 |
|---|---|---|
|
|
应用程序的整体状态。 |
|
|
构成健康状况的组件。 |
|
|
应用程序特定部分的状态。 |
|
|
构成健康状况的嵌套组件。 |
|
|
应用程序特定部分的健康状况详情。其存在由 |
上述响应字段适用于 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'
生成的响应类似于以下内容:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 101
{
"details" : {
"database" : "H2",
"validationQuery" : "isValid()"
},
"status" : "UP"
}
检索嵌套组件的健康状态
如果某个组件包含其他嵌套组件(如上例中的broker指示器所示),则可以通过向/actuator/health/{component}/{subcomponent}发出GET请求来获取该嵌套组件的运行状况,如下基于curl的示例所示:
$ curl 'http://localhost:8080/actuator/health/broker/us1' -i -X GET \
-H 'Accept: application/json'
生成的响应类似于以下内容:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 66
{
"details" : {
"version" : "1.0.2"
},
"status" : "UP"
}
应用程序运行状况的组件可以根据应用程序的运行状况指示器及其分组方式任意深度嵌套。
健康端点支持 URL 中的任意数量的 /{component} 标识符,以允许检索任何深度的组件的健康状况。