健康 (health
)
这health
endpoint 提供有关应用程序运行状况的详细信息。
检索应用程序的运行状况
要检索应用程序的运行状况,请将GET
请求/actuator/health
,如以下基于 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: 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" : 50013863936,
"threshold" : 10485760,
"path" : "/home/runner/work/spring-boot/spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/.",
"exists" : true
}
}
}
}
响应结构
响应包含应用程序运行状况的详细信息。下表描述了响应的结构:
路径 | 类型 | 描述 |
---|---|---|
|
|
应用程序的总体状态。 |
|
|
构成健康的组成部分。 |
|
|
应用程序特定部分的状态。 |
|
|
构成运行状况的嵌套组件。 |
|
|
应用程序特定部分的运行状况的详细信息。状态由 |
上面的响应字段适用于 V3 API。如果您需要返回 V2 JSON,您应该使用 accept 标头或application/vnd.spring-boot.actuator.v2+json
|
检索组件的运行状况
要检索应用程序运行状况的特定组件的运行状况,请将GET
请求/actuator/health/{component}
,如以下基于 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
{
"status" : "UP",
"details" : {
"database" : "H2",
"validationQuery" : "isValid()"
}
}
检索嵌套组件的运行状况
如果特定组件包含其他嵌套组件(如broker
indicator),可以通过发出GET
请求/actuator/health/{component}/{subcomponent}
,如以下基于 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
{
"status" : "UP",
"details" : {
"version" : "1.0.2"
}
}
应用程序运行状况的组件可以任意嵌套深度,具体取决于应用程序的运行状况指标及其分组方式。运行状况终结点支持任意数量的/{component}
标识符,以允许检索任何深度的组件的运行状况。