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.
The NATS monitoring endpoints support JSONP and CORS, making it easy to create single page monitoring web applications.
Warning:
nats-serverdoes not have authentication/authorization for the monitoring endpoint. When you plan to open yournats-serverto the internet make sure to not expose the monitoring port as well. By default monitoring binds to every interface0.0.0.0so consider setting monitoring tolocalhostor have appropriate firewall rules.
To enable the monitoring server, start the NATS server with the monitoring flag -m and the monitoring port, or turn it on in the configuration file.
Example:
To test, run nats-server -m 8222, then go to http://localhost:8222/
You can also enable monitoring using the configuration file as follows:
Binding to localhost as well:
For example, to monitor this server locally, the endpoint would be http://localhost:8222/varz. It reports various general statistics.
In addition to writing custom monitoring tools, you can monitor nats-server in Prometheus. The Prometheus NATS Exporter allows you to configure the metrics you want to observe and store in Prometheus. There's a sample Grafana dashboard that you can use to visualize the server metrics.