Monitoring Overview
NATS Server exposes HTTP endpoints for monitoring server health, performance, and operational metrics. These endpoints are essential for observability in production deployments.Enabling Monitoring
HTTP Monitoring Port
HTTPS Monitoring Port
Custom Base Path
http://localhost:8222/nats/varz
Monitoring Endpoints
From server/server.go:3037-3046, available endpoints:/varz- General server information/connz- Connection information/routez- Route information/subsz- Subscription information/jsz- JetStream information/healthz- Health check/- Endpoint index
/varz - Server Information
General server metrics and configuration.Request
Response Schema
From server/monitor.go:1211-1283:Key Metrics
Performance:cpu- Current CPU usage percentagemem- Current memory usage in bytesconnections- Active connectionsin_msgs/out_msgs- Message countsin_bytes/out_bytes- Data transfer
slow_consumers- Slow consumer disconnectionsstale_connections- Stale connection countuptime- Server uptime
max_connections- Connection limitmax_payload- Maximum message sizetls_required- TLS enforcement
/connz - Connection Information
Detailed information about client connections.Request
Query Parameters
From server/monitor.go:58-99:sort- Sort by:cid,start,subs,pending,msgs_to,msgs_from,bytes_to,bytes_from,last,idle,uptime,stop,reason,rttauth- Include username (default: false)subs- Include subscriptions (default: false)offset- Pagination offset (default: 0)limit- Pagination limit (default: 1024)cid- Filter by connection IDstate- Filter by state:open,closed,alluser- Filter by usernameacc- Filter by accountmqtt_client- Filter by MQTT client ID
Response Schema
Connection States
open- Active connectionsclosed- Recently closed connections (configurable retention)all- Both open and closed
Sorting Options
From server/monitor.go:501-528, all descending exceptcid:
ByCid- By connection ID (ascending)BySubs- By subscription countByPending- By pending bytesByOutMsgs- By messages sentByInMsgs- By messages receivedByOutBytes- By bytes sentByInBytes- By bytes receivedByLast- By last activityByIdle- By idle timeByUptime- By connection durationByRTT- By round-trip time
/routez - Route Information
Information about cluster routes.Request
Query Parameters
subs- Include subscriptions (default: false)subs=detail- Include detailed subscription info
Response Schema
/subsz - Subscription Information
Detailed subscription statistics.Request
Query Parameters
subject- Filter by subject patterntest- Test if subject matches any subscription
Response Schema
Subscription Test
/jsz - JetStream Information
JetStream metrics and status.Request
Query Parameters
accounts- Include account detailsstreams- Include stream detailsconsumers- Include consumer detailsconfig- Include configurationleader-only- Only respond if leaderoffset- Pagination offsetlimit- Pagination limit
Response Schema
/healthz - Health Check
Simple health check endpoint.Request
Response
Healthy (200 OK):JetStream Health
Include JetStream in health check:Additional Monitoring Endpoints
/gatewayz
Gateway connections and statistics.- Gateway names and remote cluster connections
- Inbound and outbound connections
- Message counts and bytes transferred
- Account information per gateway
/leafz
Leaf node connections monitoring.- Leaf node account bindings
- Connection state and RTT
- Subscription count
- Bytes in/out
/accountz
Account-level statistics.acc- Account name to query (optional, returns all if omitted)
- Connection count per account
- Subscriptions and slow consumers
- Sent/received messages and bytes
- JetStream usage if enabled
/accountstatz
Detailed account statistics over time.- Historical connection counts
- Message rate trends
- Byte transfer rates
- Resource usage patterns
/stacksz
Server stack traces for debugging.- Deadlocks
- Performance bottlenecks
- Goroutine leaks
/raftz
Raft consensus group information (JetStream clustering).- Leader and follower information
- Log indexes and terms
- Peer states
- Stream and consumer assignments
/ipqueuesz
IP-based connection queue statistics.- Pending connections per IP
- Queue depths
- Connection throttling status
Endpoint Index
Root monitoring endpoint lists available endpoints.Request
Response
HTML page with links to all monitoring endpoints.Prometheus Integration
NATS Server monitoring endpoints are compatible with Prometheus.Using nats-surveyor
The official Prometheus exporter:Custom Prometheus Exporter
Poll/varz and /connz:
Security Considerations
1. Restrict Access
Monitoring endpoints expose sensitive information:2. Use HTTPS
3. Reverse Proxy with Auth
Use nginx or similar:4. Firewall Rules
Monitoring Best Practices
1. Regular Health Checks
2. Track Key Metrics
Monitor:- Connection count
- Message rates
- Slow consumers
- Memory usage
- CPU usage
3. Set Up Alerts
- Slow consumer rate > threshold
- Memory usage > 80%
- Connection failures
- JetStream disk usage > 90%
4. Centralized Monitoring
Integrate with:- Prometheus + Grafana
- Datadog
- New Relic
- CloudWatch
5. Monitor Endpoints Performance
From/varz, check http_req_stats for endpoint usage.