2015-01-18 00:28:53 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Health Checks (HTTP)"
|
|
|
|
sidebar_current: "docs-agent-http-health"
|
|
|
|
description: >
|
2015-02-10 20:52:22 +00:00
|
|
|
The Health endpoints are used to query health-related information.
|
2015-01-18 00:28:53 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Health HTTP Endpoint
|
|
|
|
|
2015-02-10 20:52:22 +00:00
|
|
|
The Health endpoints are used to query health-related information. They are provided separately
|
|
|
|
from the Catalog since users may prefer not to use the optional health checking mechanisms.
|
|
|
|
Additionally, some of the query results from the Health endpoints are filtered while the Catalog
|
|
|
|
endpoints provide the raw entries.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
The following endpoints are supported:
|
|
|
|
|
|
|
|
* [`/v1/health/node/<node>`](#health_node): Returns the health info of a node
|
|
|
|
* [`/v1/health/checks/<service>`](#health_checks): Returns the checks of a service
|
|
|
|
* [`/v1/health/service/<service>`](#health_service): Returns the nodes and health info of a service
|
|
|
|
* [`/v1/health/state/<state>`](#health_state): Returns the checks in a given state
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
All of the health endpoints support blocking queries and all consistency modes.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
### <a name="health_node"></a> /v1/health/node/\<node\>
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
This endpoint is hit with a GET and returns the checks specific to the node
|
|
|
|
provided on the path. By default, the datacenter of the agent is queried;
|
|
|
|
however, the dc can be provided using the "?dc=" query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "serfHealth",
|
|
|
|
"Name": "Serf Health Status",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "",
|
|
|
|
"ServiceName": ""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "service:redis",
|
|
|
|
"Name": "Service 'redis' check",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "redis",
|
|
|
|
"ServiceName": "redis"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
In this case, we can see there is a system level check (that is, a check with
|
|
|
|
no associated `ServiceID`) as well as a service check for Redis. The "serfHealth" check
|
|
|
|
is special in that it is automatically present on every node. When a node
|
2015-01-18 00:28:53 +00:00
|
|
|
joins the Consul cluster, it is part of a distributed failure detection
|
|
|
|
provided by Serf. If a node fails, it is detected and the status is automatically
|
2015-02-10 20:49:21 +00:00
|
|
|
changed to `critical`.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
This endpoint supports blocking queries and all consistency modes.
|
|
|
|
|
|
|
|
### <a name="health_checks"></a> /v1/health/checks/\<service\>
|
|
|
|
|
|
|
|
This endpoint is hit with a GET and returns the checks associated with
|
2015-02-10 20:49:21 +00:00
|
|
|
the service provided on the path. By default, the datacenter of the agent is queried;
|
|
|
|
however, the dc can be provided using the "?dc=" query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-07-27 21:41:46 +00:00
|
|
|
Adding the optional "?near=" parameter with a node name will sort
|
|
|
|
the node list in ascending order based on the estimated round trip
|
2015-07-28 17:39:37 +00:00
|
|
|
time from that node. Passing "?near=_agent" will use the agent's
|
2015-07-27 21:41:46 +00:00
|
|
|
node for the sort.
|
|
|
|
|
2015-01-18 00:28:53 +00:00
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "service:redis",
|
|
|
|
"Name": "Service 'redis' check",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "redis",
|
|
|
|
"ServiceName": "redis"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
This endpoint supports blocking queries and all consistency modes.
|
|
|
|
|
|
|
|
### <a name="health_service"></a> /v1/health/service/\<service\>
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
This endpoint is hit with a GET and returns the nodes providing
|
|
|
|
the service indicated on the path. By default, the datacenter of the agent is queried;
|
|
|
|
however, the dc can be provided using the "?dc=" query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-07-27 21:41:46 +00:00
|
|
|
Adding the optional "?near=" parameter with a node name will sort
|
|
|
|
the node list in ascending order based on the estimated round trip
|
2015-07-28 17:39:37 +00:00
|
|
|
time from that node. Passing "?near=_agent" will use the agent's
|
2015-07-27 21:41:46 +00:00
|
|
|
node for the sort.
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
By default, all nodes matching the service are returned. The list can be filtered
|
2015-01-18 00:28:53 +00:00
|
|
|
by tag using the "?tag=" query parameter.
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
Providing the "?passing" query parameter, added in Consul 0.2, will filter results
|
|
|
|
to only nodes with all checks in the `passing` state. This can be used to avoid extra filtering
|
|
|
|
logic on the client side.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
This endpoint is very similar to the /v1/catalog/service endpoint; however, this
|
|
|
|
endpoint automatically returns the status of the associated health check
|
|
|
|
as well as any system level health checks. This allows a client to avoid
|
|
|
|
sending traffic to nodes that are failing health tests or reporting warnings.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
Users can also build in support for dynamic load balancing and other features
|
2015-01-18 00:28:53 +00:00
|
|
|
by incorporating the use of health checks.
|
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"Node": {
|
|
|
|
"Node": "foobar",
|
|
|
|
"Address": "10.1.10.12"
|
|
|
|
},
|
|
|
|
"Service": {
|
|
|
|
"ID": "redis",
|
|
|
|
"Service": "redis",
|
|
|
|
"Tags": null,
|
2015-11-23 14:39:05 +00:00
|
|
|
"Address": "10.1.10.12",
|
2015-01-18 00:28:53 +00:00
|
|
|
"Port": 8000
|
|
|
|
},
|
|
|
|
"Checks": [
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "service:redis",
|
|
|
|
"Name": "Service 'redis' check",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "redis",
|
|
|
|
"ServiceName": "redis"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "serfHealth",
|
|
|
|
"Name": "Serf Health Status",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "",
|
|
|
|
"ServiceName": ""
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
This endpoint supports blocking queries and all consistency modes.
|
|
|
|
|
|
|
|
### <a name="health_state"></a> /v1/health/state/\<state\>
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
This endpoint is hit with a GET and returns the checks in the
|
|
|
|
state provided on the path. By default, the datacenter of the agent is queried;
|
|
|
|
however, the dc can be provided using the "?dc=" query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-07-27 21:41:46 +00:00
|
|
|
Adding the optional "?near=" parameter with a node name will sort
|
|
|
|
the node list in ascending order based on the estimated round trip
|
2015-07-28 17:39:37 +00:00
|
|
|
time from that node. Passing "?near=_agent" will use the agent's
|
2015-07-27 21:41:46 +00:00
|
|
|
node for the sort.
|
|
|
|
|
2015-02-10 20:49:21 +00:00
|
|
|
The supported states are `any`, `unknown`, `passing`, `warning`, or `critical`.
|
|
|
|
The `any` state is a wildcard that can be used to return all checks.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "serfHealth",
|
|
|
|
"Name": "Serf Health Status",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "",
|
|
|
|
"ServiceName": ""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Node": "foobar",
|
|
|
|
"CheckID": "service:redis",
|
|
|
|
"Name": "Service 'redis' check",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "redis",
|
|
|
|
"ServiceName": "redis"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
This endpoint supports blocking queries and all consistency modes.
|