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.
Enabling monitoring
Monitoring can be enabled in or as a server . The conventional port is 8222.
As server configuration:
http_port: 8222
As a command-line option:
nats-server -m 8222
Monitoring Endpoints
General Information
The /varz endpoint returns general information about the server state and configuration.
The /connz endpoint reports more detailed information on current and recently closed connections. It uses a paging mechanism which defaults to 1024 connections.
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Arguments
Argument
Values
Description
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 it's 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
Option
Sort by
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
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.
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Arguments
Argument
Values
Description
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.
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.
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.
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Argument
Value
Description
acc
account name
Include metrics for the specified account. Default is empty. When not set, a list of all accounts is included.
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.
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Arguments
Argument
Values
Description
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.
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:
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: .
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.