Agent HTTP API
The /agent
endpoints are used to interact with the local Consul agent.
Usually, services and checks are registered with an agent which then takes on
the burden of keeping that data synchronized with the cluster. For example, the
agent registers services and checks with the Catalog and performs
anti-entropy to recover from outages.
In addition to these endpoints, additional endpoints are grouped in the
navigation for Checks
and Services
.
Retrieve host information
This endpoint returns information about the host the agent is running on such as CPU, memory, and disk.
Note: this is not a stable API. The structure of the response body may change at any time. If you require this data to be in a stable format, please open a GitHub issue to discuss your use case.
Method | Path | Produces |
---|---|---|
GET | /agent/host | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | operator:read |
Sample Request
Sample Response
Retrieve version information
This endpoint returns version information about Consul.
Method | Path | Produces |
---|---|---|
GET | /agent/version | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | none |
List Members
This endpoint returns the members the agent sees in the cluster gossip pool. Due
to the nature of gossip, this is eventually consistent: the results may differ
by agent. The strongly consistent view of nodes is instead provided by
/v1/catalog/nodes
.
The HTTP response includes the X-Consul-Results-Filtered-By-ACLs: true
header
if the response array excludes results due to ACL policy configuration.
Refer to the HTTP API documentation for more information.
Method | Path | Produces |
---|---|---|
GET | /agent/members | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | node:read |
The corresponding CLI command is consul members
.
Query Parameters
wan
(bool: false)
- Specifies to list WAN members instead of the LAN members (which is the default). This is only eligible for agents running in server mode.segment
(string: "")
Enterprise - Specifies the segment to list members for. If left blank, this will query for the default segment when connecting to a server and the agent's own segment when connecting to a client (clients can only be part of one network segment). When querying a server, setting this to the special string_all
will show members in all segments.
partition
(string: "")
Enterprise - The admin partition to use. If not provided, the partition is inferred from the request's ACL token, or defaults to thedefault
partition.
Sample Request
Sample Response
Read Configuration
This endpoint returns the configuration and member information of the local
agent. The Config
element contains a subset of the configuration and its
format will not change in a backwards incompatible way between releases.
DebugConfig
contains the full runtime configuration but its format is subject
to change without notice or deprecation.
Method | Path | Produces |
---|---|---|
GET | /agent/self | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:read |
Sample Request
Sample Response
Reload Agent
This endpoint instructs the agent to reload its configuration. Any errors encountered during this process are returned.
Not all configuration options are reloadable. See the Reloadable Configuration section on the agent options page for details on which options are supported.
Method | Path | Produces |
---|---|---|
PUT | /agent/reload | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:write |
The corresponding CLI command is consul reload
.
Sample Request
Enable Maintenance Mode
This endpoint places the agent into "maintenance mode". During maintenance mode, the node will be marked as unavailable and will not be present in DNS or API queries. This API call is idempotent.
Maintenance mode is persistent and will be automatically restored on agent restart.
Method | Path | Produces |
---|---|---|
PUT | /agent/maintenance | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | node:write |
The corresponding CLI command is consul maint
.
Query Parameters
enable
(bool: <required>)
- Specifies whether to enable or disable maintenance mode.reason
(string: "")
- Specifies a text string explaining the reason for placing the node into maintenance mode. This is simply to aid human operators. If no reason is provided, a default value is used instead. This parameter must be URI-encoded.
Sample Request
View Metrics
This endpoint will dump the metrics for the most recent finished interval. For more information about metrics, see the telemetry page.
In order to enable Prometheus support, you need to use the
configuration directive
prometheus_retention_time
.
Since Consul 1.7.2 this endpoint will also automatically switch output format if
the request contains an Accept
header with a compatible MIME type such as
application/openmetrics-text
. Prometheus v2.5.0 and newer pass this header in scraping
queries, and so will get a compatible format by default. Older versions of Prometheus may
work by default as several previously used MIME types are also detected, but the ?format
query parameter may also be used to specify the output format manually if needed.
simplifying scrape configuration.
Note: If using the default format and your metric includes labels that use the same key name multiple times (i.e. tag=tag2 and tag=tag1), only the sorted last value (tag=tag2) will be visible on this endpoint due to a display issue. The complete label set is correctly applied and passed to external metrics providers even though it is not visible through this endpoint.
Method | Path | Produces |
---|---|---|
GET | /agent/metrics | application/json |
GET | /agent/metrics?format=prometheus | text/plain; version=0.0.4; charset=utf-8 |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:read |
Sample Request
Sample Response
Timestamp
is the timestamp of the interval for the displayed metrics. Metrics are aggregated on a ten second interval, so this value (along with the displayed metrics) will change every ten seconds.Gauges
is a list of gauges which store one value that is updated as time goes on, such as the amount of memory allocated.Points
is a list of point metrics, which each store a series of points under a given name.Counters
is a list of counters, which store info about a metric that is incremented over time such as the number of requests to an HTTP endpoint.Samples
is a list of samples, which store info about the amount of time spent on an operation, such as the time taken to serve a request to a specific http endpoint.
Stream Logs
This endpoint streams logs from the local agent until the connection is closed.
Method | Path | Produces |
---|---|---|
GET | /agent/monitor | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:read |
Query Parameters
loglevel
(string: "info")
- Specifies a text string containing a log level to filter on, such asinfo
.logjson
(bool: false)
- Specifies whether the logs will be output in JSON format.
Sample Request
Sample Response
Join Agent
This endpoint instructs the agent to attempt to connect to a given address.
Method | Path | Produces |
---|---|---|
PUT | /agent/join/:address | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:write |
The corresponding CLI command is consul join
.
Path Parameters
address
(string: <required>)
- Specifies the address of the other agent to join.
Query Parameters
wan
(bool: false)
- Specifies to try and join over the WAN pool. This is only optional for agents running in server mode.
Sample Request
Graceful Leave and Shutdown
This endpoint triggers a graceful leave and shutdown of the agent. It is used to ensure other nodes see the agent as "left" instead of "failed". Nodes that leave will not attempt to re-join the cluster on restarting with a snapshot.
For nodes in server mode, the node is removed from the Raft peer set in a graceful manner. This is critical, as in certain situations a non-graceful leave can affect cluster availability.
Method | Path | Produces |
---|---|---|
PUT | /agent/leave | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:write |
The corresponding CLI command is consul leave
.
Sample Request
Force Leave and Shutdown
This endpoint instructs the agent to force a node into the left
state in the
LAN and WAN gossip pools. If a node fails unexpectedly, then it will be in a failed
state. Once in the
failed
state, Consul will attempt to reconnect, and the services and checks
belonging to that node will not be cleaned up. Forcing a node into the left
state allows its old entries to be removed.
Method | Path | Produces |
---|---|---|
PUT | /agent/force-leave/:node_name | application/json |
Additionally, by specifying the prune
flag, a node can be forcibly removed from
the list of members entirely.
Method | Path | Produces |
---|---|---|
PUT | /agent/force-leave/:node_name?prune | application/json |
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | operator:write |
The corresponding CLI command is consul force-leave
.
Path Parameters
node_name
(string: <required>)
- Specifies the name of the node to be forced intoleft
state.
Query Parameters
prune
(bool: false)
- Specifies whether to forcibly remove the node from the list of members. Pruning a node in theleft
orfailed
state removes it from the list altogether. Added in Consul 1.6.2.wan
(bool: false)
- Specifies the node should only be removed from the WAN gossip pool. Added in Consul 1.11.0.
Sample Request
Update ACL Tokens
This endpoint updates the ACL tokens currently in use by the agent. It can be
used to introduce ACL tokens to the agent for the first time, or to update
tokens that were initially loaded from the agent's configuration. Tokens will be persisted
only if the acl.enable_token_persistence
configuration is true
. When not being persisted, they will need to be reset if the agent
is restarted.
Method | Path | Produces |
---|---|---|
PUT | /agent/token/default | application/json |
PUT | /agent/token/agent | application/json |
PUT | /agent/token/agent_recovery | application/json |
PUT | /agent/token/config_file_service_registration | application/json |
PUT | /agent/token/replication | application/json |
The paths above correspond to the token names as found in the agent configuration:
default
, agent
,
agent_recovery
,
config_file_service_registration
,
and replication
.
Deprecation Note: The following paths were deprecated in version 1.11
Method | Path | Produces |
---|---|---|
PUT | /agent/token/agent_master | application/json |
The paths above correspond to the token names as found in the agent configuration:
agent_master
.
Deprecation Note: The following paths were deprecated in version 1.4.3
Method | Path | Produces |
---|---|---|
PUT | /agent/token/acl_token | application/json |
PUT | /agent/token/acl_agent_token | application/json |
PUT | /agent/token/acl_agent_master_token | application/json |
PUT | /agent/token/acl_replication_token | application/json |
The paths above correspond to the token names as found in the agent configuration:
acl_token
, acl_agent_token
,
acl_agent_master_token
, and
acl_replication_token
.
The table below shows this endpoint's support for blocking queries, consistency modes, agent caching, and required ACLs.
Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
---|---|---|---|
NO | none | none | agent:write |
The corresponding CLI command is consul acl set-agent-token
.
JSON Request Body Schema
Token
(string: "")
- Specifies the ACL token to set.
Sample Payload
Sample Request