Configuring Monitoring

NATS Server 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.

The NATS monitoring endpoints support JSONP and CORS, making it easy to create single page monitoring web applications.

Warning: 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 from the command line

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.

  1. -m, --http_port PORT HTTP PORT for monitoring
  2. -ms,--https_port PORT Use HTTPS PORT for monitoring

Example:

  1. nats-server -m 8222

Output

  1. [4528] 2019/06/01 20:09:58.572939 [INF] Starting nats-server version 2.0.0
  2. [4528] 2019/06/01 20:09:58.573007 [INF] Starting http monitor on port 8222
  3. [4528] 2019/06/01 20:09:58.573071 [INF] Listening for client connections on 0.0.0.0:4222
  4. [4528] 2019/06/01 20:09:58.573090 [INF] nats-server is ready</td>

To test, run nats-server -m 8222, then go to http://localhost:8222/

Enable monitoring from the configuration file

You can also enable monitoring using the configuration file as follows:

  1. http_port: 8222

Binding to localhost as well:

  1. http: localhost:8222

For example, to monitor this server locally, the endpoint would be http://localhost:8222/varz. It reports various general statistics.

Monitoring Tools

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.