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\>
|
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
This endpoint is hit with a `GET` and returns the checks specific to the node
|
2015-02-10 20:49:21 +00:00
|
|
|
provided on the path. By default, the datacenter of the agent is queried;
|
2016-11-25 17:34:07 +00:00
|
|
|
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
|
|
|
|
[
|
|
|
|
{
|
2017-01-18 22:26:42 +00:00
|
|
|
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
|
|
|
|
"Node": "foobar",
|
2015-01-18 00:28:53 +00:00
|
|
|
"CheckID": "serfHealth",
|
|
|
|
"Name": "Serf Health Status",
|
|
|
|
"Status": "passing",
|
|
|
|
"Notes": "",
|
|
|
|
"Output": "",
|
|
|
|
"ServiceID": "",
|
|
|
|
"ServiceName": ""
|
|
|
|
},
|
|
|
|
{
|
2017-01-18 22:26:42 +00:00
|
|
|
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
|
2015-01-18 00:28:53 +00:00
|
|
|
"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
|
2016-11-25 17:34:07 +00:00
|
|
|
no associated `ServiceID`) as well as a service check for Redis. The `serfHealth` check
|
2015-02-10 20:49:21 +00:00
|
|
|
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\>
|
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
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;
|
2016-11-25 17:34:07 +00:00
|
|
|
however, the `dc` can be provided using the `?dc=` query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
Adding the optional `?near=` parameter with a node name will sort
|
2015-07-27 21:41:46 +00:00
|
|
|
the node list in ascending order based on the estimated round trip
|
2016-11-25 17:34:07 +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.
|
|
|
|
|
2017-01-14 01:08:43 +00:00
|
|
|
In Consul 0.7.3 and later, the optional `?node-meta=` parameter can be
|
|
|
|
provided with a desired node metadata key/value pair of the form `key:value`.
|
|
|
|
This parameter can be specified multiple times, and will filter the results to
|
|
|
|
health checks on nodes with the specified key/value pair(s).
|
|
|
|
|
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\>
|
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
This endpoint is hit with a `GET` and returns the nodes providing
|
2015-02-10 20:49:21 +00:00
|
|
|
the service indicated on the path. By default, the datacenter of the agent is queried;
|
2016-11-25 17:34:07 +00:00
|
|
|
however, the `dc` can be provided using the `?dc=` query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
Adding the optional `?near=` parameter with a node name will sort
|
2015-07-27 21:41:46 +00:00
|
|
|
the node list in ascending order based on the estimated round trip
|
2016-11-25 17:34:07 +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
|
2017-01-25 13:34:56 +00:00
|
|
|
by tag using the `?tag=` query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 17:34:07 +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
|
|
|
|
2017-01-14 01:08:43 +00:00
|
|
|
In Consul 0.7.3 and later, the optional `?node-meta=` parameter can be
|
|
|
|
provided with a desired node metadata key/value pair of the form `key:value`.
|
|
|
|
This parameter can be specified multiple times, and will filter the results to
|
|
|
|
nodes with the specified key/value pair(s).
|
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
This endpoint is very similar to the `/v1/catalog/service` endpoint; however, this
|
2015-02-10 20:49:21 +00:00
|
|
|
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": {
|
2017-01-18 22:26:42 +00:00
|
|
|
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
|
2015-01-18 00:28:53 +00:00
|
|
|
"Node": "foobar",
|
2016-02-07 18:56:47 +00:00
|
|
|
"Address": "10.1.10.12",
|
|
|
|
"TaggedAddresses": {
|
2016-08-16 17:49:03 +00:00
|
|
|
"lan": "10.1.10.12",
|
2016-02-07 18:56:47 +00:00
|
|
|
"wan": "10.1.10.12"
|
2017-01-11 23:44:13 +00:00
|
|
|
},
|
|
|
|
"Meta": {
|
|
|
|
"instance_type": "t2.medium"
|
2016-02-07 18:56:47 +00:00
|
|
|
}
|
2015-01-18 00:28:53 +00:00
|
|
|
},
|
|
|
|
"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\>
|
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
This endpoint is hit with a `GET` and returns the checks in the
|
2015-02-10 20:49:21 +00:00
|
|
|
state provided on the path. By default, the datacenter of the agent is queried;
|
2016-11-25 17:34:07 +00:00
|
|
|
however, the `dc` can be provided using the `?dc=` query parameter.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 17:34:07 +00:00
|
|
|
Adding the optional `?near=` parameter with a node name will sort
|
2015-07-27 21:41:46 +00:00
|
|
|
the node list in ascending order based on the estimated round trip
|
2016-11-25 17:34:07 +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.
|
|
|
|
|
2017-01-14 01:08:43 +00:00
|
|
|
In Consul 0.7.3 and later, the optional `?node-meta=` parameter can be
|
|
|
|
provided with a desired node metadata key/value pair of the form `key:value`.
|
|
|
|
This parameter can be specified multiple times, and will filter the results to
|
|
|
|
health checks on nodes with the specified key/value pair(s).
|
|
|
|
|
2016-09-21 13:50:12 +00:00
|
|
|
The supported states are `any`, `passing`, `warning`, or `critical`.
|
2015-02-10 20:49:21 +00:00
|
|
|
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.
|