健康 (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} 識別符號,以允許獲取任何深度的元件健康狀況。