DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your NATS Messaging System with Vigilmon

How to Monitor Your NATS Messaging System with Vigilmon

NATS is a high-performance, cloud-native messaging system used by teams building distributed systems, microservices, and event-driven architectures. Unlike heavier brokers, NATS is fast, lightweight, and designed for simplicity — but that simplicity can hide gaps in observability.

This guide shows you how to set up external uptime monitoring for NATS with Vigilmon.

Why Monitor NATS Externally?

NATS exposes a built-in HTTP monitoring endpoint at port 8222 by default. This gives you real-time stats. But internal metrics do not tell you whether your NATS server is reachable from the outside world.

External monitoring answers:

  • Is the NATS server reachable over the network?
  • Is the monitoring HTTP endpoint responding?

Step 1: Enable the NATS HTTP Monitoring Port

NATS ships with monitoring disabled by default. Enable it in your config:

port: 4222
http_port: 8222
Enter fullscreen mode Exit fullscreen mode

Test the monitoring endpoint:

curl http://localhost:8222/varz
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Health Endpoint

The built-in /varz endpoint is verbose. Expose a simple health route:

const { connect } = require('nats');
const http = require('http');

let isConnected = false;

async function main() {
  try {
    const nc = await connect({ servers: 'nats://localhost:4222' });
    isConnected = true;
  } catch (err) {
    isConnected = false;
  }

  http.createServer((req, res) => {
    if (req.url === '/health') {
      if (isConnected) {
        res.writeHead(200);
        res.end(JSON.stringify({ status: 'ok', nats: 'connected' }));
      } else {
        res.writeHead(503);
        res.end(JSON.stringify({ status: 'error', nats: 'disconnected' }));
      }
    }
  }).listen(3000);
}

main();
Enter fullscreen mode Exit fullscreen mode

Step 3: Add to Vigilmon

  1. Log in at vigilmon.online
  2. Click + Add Monitor
  3. Set the URL: https://your-service.example.com/health
  4. Set check interval: 1 minute
  5. Set expected status: 200

What to Monitor

What to Monitor How
NATS server reachability HTTP check on 8222/varz
Application NATS connection Custom /health endpoint

NATS is fast and reliable — but your monitoring needs to be external to be meaningful. Set up your Vigilmon monitor once, and you'll know the instant NATS becomes unreachable.


Vigilmon provides free uptime monitoring for NATS and any HTTP endpoint.

Top comments (0)