Monitoring
Last updated
Was this helpful?
Last updated
Was this helpful?
To monitor the NATS messaging system, nats-server
provides a lightweight HTTP server on a dedicated monitoring port. The monitoring server provides several endpoints, providing statistics and other information about the following:
All endpoints return a JSON object.
The NATS monitoring endpoints support and , making it easy to create single page monitoring web applications. Part of the NATS ecosystem is a tool called that visualizes data from these endpoints on the command line.
nats-server
does not have authentication/authorization for the monitoring endpoint. When you plan to open your nats-server
to the internet make sure to not expose the monitoring port as well. By default, monitoring binds to every interface 0.0.0.0
so consider setting monitoring to localhost
or have appropriate firewall rules.
As server configuration:
As a command-line option:
(/varz)
The /varz
endpoint returns general information about the server state and configuration.
Success
200 (OK)
Error
400 (Bad Request)
N/A
/connz
)The /connz
endpoint reports more detailed information on current and recently closed connections. It uses a paging mechanism which defaults to 1024 connections.
Success
200 (OK)
Error
400 (Bad Request)
sort
(see sort options)
Sorts the results. Default is connection ID.
auth
true, 1, false, 0
Include username. Default is false.
subs
true, 1, false, 0 or detail
Include subscriptions. Default is false. When set to detail
a list with more detailed subscription information will be returned.
offset
number > 0
Pagination offset. Default is 0.
limit
number > 0
Number of results to return. Default is 1024.
cid
number, valid id
Return a connection by its id
state
open, *closed, any
Return connections of particular state. Default is open.
mqtt_client
string
Filter the connection with this MQTT client ID.
The server will default to holding the last 10,000 closed connections.
Sort Options
cid
Connection ID
start
Connection start time, same as CID
subs
Number of subscriptions
pending
Amount of data in bytes waiting to be sent to client
msgs_to
Number of messages sent
msgs_from
Number of messages received
bytes_to
Number of bytes sent
bytes_from
Number of bytes received
last
Last activity
idle
Amount of inactivity
uptime
Lifetime of the connection
stop
Stop time for a closed connection
reason
Reason for a closed connection
rtt
Round trip time
/routez
)The /routez
endpoint reports information on active routes for a cluster. Routes are expected to be low, so there is no paging mechanism with this endpoint.
Success
200 (OK)
Error
400 (Bad Request)
subs
true, 1, false, 0 or detail
Include subscriptions. Default is false. When set to detail
a list with more detailed subscription information will be returned.
/gatewayz
)The /gatewayz
endpoint reports information about gateways used to create a NATS supercluster. Like routes, the number of gateways are expected to be low, so there is no paging mechanism with this endpoint.
Success
200 (OK)
Error
400 (Bad Request)
accs
true, 1, false, 0
Include account information. Default is false.
gw_name
string
Return only remote gateways with this name.
acc_name
string
Limit the list of accounts to this account name.
/leafz
)The /leafz
endpoint reports detailed information about the leaf node connections.
Success
200 (OK)
Error
400 (Bad Request)
subs
true, 1, false, 0
Include internal subscriptions. Default is false.
/subsz
)The /subsz
endpoint reports detailed information about the current subscriptions and the routing data structure. It is not normally used.
Success
200 (OK)
Error
400 (Bad Request)
subs
true, 1, false, 0
Include subscriptions. Default is false.
offset
integer > 0
Pagination offset. Default is 0.
limit
integer > 0
Number of results to return. Default is 1024.
test
subject
Test whether a subsciption exists.
/accountz
)The /accountz
endpoint reports information on a server's active accounts. The default behavior is to return a list of all accounts known to the server.
Success
200 (OK)
Error
400 (Bad Request)
acc
account name
Include metrics for the specified account. Default is empty. When not set, a list of all accounts is included.
Default behavior:
Retrieve specific account:
/accstatz
)The /accstatz
endpoint reports per-account statistics such as the number of connections, messages/bytes in/out, etc.
Success
200 (OK)
Error
400 (Bad Request)
unused
true, 1, false, 0
If true, include accounts that do not have any current connections. Default is false.
/jsz
)The /jsz
endpoint reports more detailed information on JetStream. For accounts, it uses a paging mechanism that defaults to 1024 connections.
Note: If you're in a clustered environment, it is recommended to retrieve the information from the stream's leader in order to get the most accurate and up-to-date data.
Success
200 (OK)
Error
400 (Bad Request)
acc
account name
Include metrics for the specified account. Default is unset.
accounts
true, 1, false, 0
Include account specific JetStream information. Default is false.
streams
true, 1, false, 0
Include streams. When set, implies accounts=true
. Default is false.
consumers
true, 1, false, 0
Include consumer. When set, implies streams=true
. Default is false.
config
true, 1, false, 0
When stream or consumer are requested, include their respective configuration. Default is false.
leader-only
true, 1, false, 0
Only the leader responds. Default is false.
offset
number > 0
Pagination offset. Default is 0.
limit
number > 0
Number of results to return. Default is 1024.
raft
true, 1, false, 0
Include information details about the Raft group. Default is false.
/healthz
)The /healthz
endpoint returns OK if the server is able to accept connections.
Success
200 (OK)
Error
400 (Bad Request)
js-enabled-only
true, 1
Returns an error if JetStream is disabled.
js-server-only
true, 1
Skip health check of accounts, streams, and consumers.
js-enabled
true, 1
Returns an error if JetStream is disabled. (Deprecated: use js-enabled-only
instead).
For example:
Here is a JQuery example implementation:
Monitoring can be enabled in or as a server . The conventional port is 8222
.
Once the server is running using one of the two methods, go to to browse the available endpoints detailed below.
Get up to 1024 connections:
Control limit and offset: .
Get closed connection information: .
You can also report detailed subscription information on a per connection basis using subs=1. For example: .
As noted above, the routez
endpoint does support the subs
argument from the /connz
endpoint. For example:
Get route information:
Retrieve Gateway Information:
As noted above, the leafz
endpoint does support the subs
argument from the /connz
endpoint. For example:
Get leaf nodes information:
Get subscription routing information:
Get list of all accounts:
Get details for specific account $G
:
Accounts with active connections -
Include ones without any connections (in this case $SYS
)-
Get basic JetStream information:
Request accounts and control limit and offset: .
You can also report detailed consumer information on a per connection basis using consumer=true. For example: .
Default -
Expect JetStream -
NATS monitoring endpoints support and . You can easily create single page web applications for monitoring. To do this you simply pass the callback
query parameter to any endpoint.
In addition to writing custom monitoring tools, you can monitor nats-server in Prometheus. The allows you to configure the metrics you want to observe and store in Prometheus, and there are Grafana dashboards available for you to visualize the server metrics.
See the for more details.