Overview
NATS Server provides a comprehensive set of built-in HTTP monitoring endpoints that expose real-time server metrics, connection details, and operational statistics. These endpoints enable deep observability into your NATS infrastructure without requiring external agents.All monitoring endpoints are exposed via HTTP on a configurable port (default: 8222) and return JSON-formatted data.
HTTP Monitoring Port
Configuration
Enable monitoring by configuring the HTTP port:monitoring.conf
CLI Flags
/varz- Server information and statistics/connz- Connection details/routez- Route connection information/subsz- Subscription details/jsz- JetStream statistics
HTTPS Configuration
Secure monitoring endpoints with TLS:https-monitoring.conf
Monitoring Endpoints
/varz - Server Information
Provides comprehensive server runtime information and statistics.Basic Usage
Unique server ID generated at start
NATS Server version
Current number of active connections
Total connections since server start
Total inbound messages
Total outbound messages
Total inbound bytes
Total outbound bytes
Number of slow consumers detected
Current active subscriptions
Current CPU usage percentage
Current memory usage in bytes
JetStream configuration and statistics (if enabled)
/connz - Connection Details
Provides detailed information about client connections.Basic Usage
Sort connections by:
cid, start, subs, pending, msgs_to, msgs_from, bytes_to, bytes_from, last, idle, uptime, stop, reason, rttInclude username in connection details
Include subscription subjects
Include detailed subscription information
Pagination offset
Maximum connections to return
Filter by specific connection ID
Filter by state:
open, closed, allFilter by MQTT client ID
Connection Info
/routez - Route Information
Details about route (server-to-server) connections in a cluster.Basic Usage
Include subscription details for routes
Include detailed subscription information
/subsz - Subscription Details
Information about active subscriptions across all connections.Basic Usage
Include detailed subscription list
Pagination offset
Maximum subscriptions to return
Test which subscriptions match a publish subject
/jsz - JetStream Statistics
Detailed JetStream metrics including streams, consumers, and storage usage.Basic Usage
Include per-account JetStream details
Include stream details
Include consumer details
Include configuration details
Only return data if server is meta-leader
Pagination offset for accounts
Maximum accounts to return
Integration with Monitoring Tools
Prometheus
Use the NATS Prometheus Exporter:prometheus.yml
Run Exporter
Grafana
Import official NATS Grafana dashboards:- NATS Server Dashboard: General server metrics
- JetStream Dashboard: Stream and consumer metrics
- Connection Dashboard: Client connection details
DataDog
Use the DataDog NATS integration:datadog.yaml
Custom Monitoring
Build custom monitoring with polling:Custom Monitor
Metrics and Observability
Key Metrics to Monitor
Connection Count
Monitor
connections and total_connections for client activity trends.Message Throughput
Track
in_msgs, out_msgs, in_bytes, out_bytes for throughput.Slow Consumers
Alert on
slow_consumers increasing to detect backpressure.Memory Usage
Monitor
mem and JetStream memory to prevent OOM.CPU Usage
Watch
cpu percentage for performance issues.Subscription Count
Track
subscriptions for interest patterns.JetStream Storage
Monitor JetStream
storage vs max_storage limits.API Errors
Alert on JetStream API
errors increasing.Health Checks
Use/healthz for health monitoring:
Health Check
JetStream Health
Real-Time Monitoring Example
Live Dashboard
Security Considerations
Authentication
Restrict monitoring endpoint access:Secured Monitoring
Network Restrictions
Bind to localhost or internal network:Restricted Access
Next Steps
JetStream
Monitor JetStream streams and consumers
Configuration
Advanced monitoring configuration
Operations
Operational best practices
Prometheus Exporter
Official Prometheus integration