Monitoring
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
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.
Warning:
nats-server
does not have authentication/authorization for the monitoring endpoint. When you plan to open yournats-server
to the internet make sure to not expose the monitoring port as well. By default monitoring binds to every interface0.0.0.0
so consider setting monitoring tolocalhost
or have appropriate firewall rules.In other words don't do what
http://demo.nats.io:8222/
does! It is done on purpose to simplify the examples below.
To enable the monitoring server, start the NATS server with the monitoring flag -m
and the monitoring port, or turn it on in the .
Example:
You can also enable monitoring using the configuration file as follows:
Binding to localhost
as well:
The following sections describe each supported monitoring endpoint: varz
, connz
, routez
, subsz
, gatewayz
, and leafz
. There are not any required arguments, however use of arguments can let you tailor monitoring to your environment and tooling.
The /varz
endpoint returns general information about the server state and configuration.
Endpoint: http://server:port/varz
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
N/A
The /connz
endpoint reports more detailed information on current and recently closed connections. It uses a paging mechanism which defaults to 1024 connections.
Endpoint: http://server:port/connz
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
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.
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
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
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.
Endpoint: http://server:port/routez
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
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.
Endpoint: http://server:port/gatewayz
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Argument
Values
Description
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.
The /leafz
endpoint reports detailed information about the leaf node connections.
Endpoint: http://server:port/leafz
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Argument
Values
Description
subs
true, 1, false, 0
Include internal subscriptions. Default is false.
The /subsz
endpoint reports detailed information about the current subscriptions and the routing data structure. It is not normally used.
Endpoint: http://server:port/subsz
Result
Return Code
Success
200 (OK)
Error
400 (Bad Request)
Argument
Values
Description
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.
For example:
Here is a JQuery example implementation:
To test, run nats-server -m 8222
, then go to
For example, to monitor this server locally, the endpoint would be . It reports various general statistics.
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:
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. There's a sample dashboard that you can use to visualize the server metrics.