健康 (health)
health 端点提供了应用程序健康状况的详细信息。
获取应用程序健康状况
要获取应用程序的健康状况,请向 /actuator/health 发送 GET 请求,如下面的基于 curl 的示例所示:
$ curl 'https://:8080/actuator/health' -i -X GET \
-H 'Accept: application/json'
结果响应类似于以下内容
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 806
{
"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" : 76887154688,
"free" : 47739019264,
"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,应使用接受头或 application/vnd.spring-boot.actuator.v2+json |
获取组件的健康状况
要获取应用程序健康状况中特定组件的健康状况,请向 /actuator/health/{component} 发送 GET 请求,如下面的基于 curl 的示例所示:
$ curl 'https://: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 'https://: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} 标识符,以允许获取任何深度的组件健康状况。