健康(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: 847

{
  "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" : 245107195904,
        "free" : 112550883328,
        "threshold" : 10485760,
        "path" : "/Users/zhaiyongchao/Documents/spring-docs-translation/spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/.",
        "exists" : true
      }
    }
  }
}

响应结构

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

Path Type Description

status

String

Overall status of the application.

components

Object

The components that make up the health.

components.*.status

String

Status of a specific part of the application.

components.*.components

Object

The nested components that make up the health.

components.*.details

Object

Details of the health of a specific part of the application. Presence is controlled by 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'

返回结果类似如下:

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

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

响应结构

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

Path Type Description

status

String

Status of a specific part of the application

details

Object

Details of the health of a specific part of the application.

获取嵌套组件的健康状况

如果某个组件包含其他嵌套组件(如上例中的 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

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

应用程序的健康组件可以根据健康指示器的分组方式任意嵌套。 health 端点支持 URL 中任意数量的 /{component} 标识符,以便获取任意深度组件的健康状况。

响应结构

响应包含应用程序某个组件实例健康状况的详细信息。 下表描述了响应的结构:

Path Type Description

status

String

Status of a specific part of the application

details

Object

Details of the health of a specific part of the application.