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
Test the monitoring endpoint:
curl http://localhost:8222/varz
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();
Step 3: Add to Vigilmon
- Log in at vigilmon.online
- Click + Add Monitor
- Set the URL:
https://your-service.example.com/health - Set check interval: 1 minute
- 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)