Skip to main content

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
Command line flags:
CLI Flags
From server.go:3037-3046, the following paths are available:
  • /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 expose sensitive information. Always secure them with TLS and authentication in production.

Monitoring Endpoints

/varz - Server Information

Provides comprehensive server runtime information and statistics.
Basic Usage
Key Fields (from monitor.go:1211-1283):
string
Unique server ID generated at start
string
NATS Server version
int
Current number of active connections
uint64
Total connections since server start
int64
Total inbound messages
int64
Total outbound messages
int64
Total inbound bytes
int64
Total outbound bytes
int64
Number of slow consumers detected
uint32
Current active subscriptions
float64
Current CPU usage percentage
int64
Current memory usage in bytes
object
JetStream configuration and statistics (if enabled)

/connz - Connection Details

Provides detailed information about client connections.
Basic Usage
Query Parameters:
string
default:"cid"
Sort connections by: cid, start, subs, pending, msgs_to, msgs_from, bytes_to, bytes_from, last, idle, uptime, stop, reason, rtt
bool
default:"false"
Include username in connection details
bool
default:"false"
Include subscription subjects
bool
default:"false"
Include detailed subscription information
int
default:"0"
Pagination offset
int
default:"1024"
Maximum connections to return
uint64
Filter by specific connection ID
string
Filter by state: open, closed, all
string
Filter by MQTT client ID
Response Fields (from monitor.go:47-154):
Connection Info

/routez - Route Information

Details about route (server-to-server) connections in a cluster.
Basic Usage
Query Parameters:
bool
default:"false"
Include subscription details for routes
bool
default:"false"
Include detailed subscription information

/subsz - Subscription Details

Information about active subscriptions across all connections.
Basic Usage
Query Parameters:
bool
default:"false"
Include detailed subscription list
int
default:"0"
Pagination offset
int
default:"1024"
Maximum subscriptions to return
string
Test which subscriptions match a publish subject

/jsz - JetStream Statistics

Detailed JetStream metrics including streams, consumers, and storage usage.
Basic Usage
Query Parameters:
bool
default:"false"
Include per-account JetStream details
bool
default:"false"
Include stream details
bool
default:"false"
Include consumer details
bool
default:"false"
Include configuration details
bool
default:"false"
Only return data if server is meta-leader
int
default:"0"
Pagination offset for accounts
int
default:"1024"
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
Configure health check options:
JetStream Health

Real-Time Monitoring Example

Live Dashboard

Security Considerations

Monitoring endpoints expose sensitive operational data. Always secure them in production.

Authentication

Restrict monitoring endpoint access:
Secured Monitoring

Network Restrictions

Bind to localhost or internal network:
Restricted Access
Use firewall rules to restrict access to monitoring ports.

Next Steps

JetStream

Monitor JetStream streams and consumers

Configuration

Advanced monitoring configuration

Operations

Operational best practices

Prometheus Exporter

Official Prometheus integration