Skip to main content

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

Or via command line:

HTTPS Monitoring Port

Or via command line:

Custom Base Path

Endpoints available at: 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 percentage
  • mem - Current memory usage in bytes
  • connections - Active connections
  • in_msgs / out_msgs - Message counts
  • in_bytes / out_bytes - Data transfer
Health:
  • slow_consumers - Slow consumer disconnections
  • stale_connections - Stale connection count
  • uptime - Server uptime
Configuration:
  • max_connections - Connection limit
  • max_payload - Maximum message size
  • tls_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, rtt
  • auth - Include username (default: false)
  • subs - Include subscriptions (default: false)
  • offset - Pagination offset (default: 0)
  • limit - Pagination limit (default: 1024)
  • cid - Filter by connection ID
  • state - Filter by state: open, closed, all
  • user - Filter by username
  • acc - Filter by account
  • mqtt_client - Filter by MQTT client ID

Response Schema

Connection States

  • open - Active connections
  • closed - Recently closed connections (configurable retention)
  • all - Both open and closed

Sorting Options

From server/monitor.go:501-528, all descending except cid:
  • ByCid - By connection ID (ascending)
  • BySubs - By subscription count
  • ByPending - By pending bytes
  • ByOutMsgs - By messages sent
  • ByInMsgs - By messages received
  • ByOutBytes - By bytes sent
  • ByInBytes - By bytes received
  • ByLast - By last activity
  • ByIdle - By idle time
  • ByUptime - By connection duration
  • ByRTT - 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 pattern
  • test - Test if subject matches any subscription

Response Schema

Subscription Test

Returns whether any subscriptions match the test subject.

/jsz - JetStream Information

JetStream metrics and status.

Request

Query Parameters

  • accounts - Include account details
  • streams - Include stream details
  • consumers - Include consumer details
  • config - Include configuration
  • leader-only - Only respond if leader
  • offset - Pagination offset
  • limit - Pagination limit

Response Schema

/healthz - Health Check

Simple health check endpoint.

Request

Response

Healthy (200 OK):
Unhealthy (503 Service Unavailable):

JetStream Health

Include JetStream in health check:
Returns 503 if JetStream is not enabled or unhealthy.

Additional Monitoring Endpoints

/gatewayz

Gateway connections and statistics.
Returns information about gateway connections between clusters including:
  • Gateway names and remote cluster connections
  • Inbound and outbound connections
  • Message counts and bytes transferred
  • Account information per gateway

/leafz

Leaf node connections monitoring.
Displays leaf node connections:
  • Leaf node account bindings
  • Connection state and RTT
  • Subscription count
  • Bytes in/out

/accountz

Account-level statistics.
Query parameters:
  • acc - Account name to query (optional, returns all if omitted)
Returns account details:
  • Connection count per account
  • Subscriptions and slow consumers
  • Sent/received messages and bytes
  • JetStream usage if enabled

/accountstatz

Detailed account statistics over time.
Provides time-series statistics for accounts including:
  • Historical connection counts
  • Message rate trends
  • Byte transfer rates
  • Resource usage patterns

/stacksz

Server stack traces for debugging.
Returns Go runtime stack traces for all goroutines. Useful for debugging:
  • Deadlocks
  • Performance bottlenecks
  • Goroutine leaks
Stack dumps can be large and may impact performance. Use only for debugging.

/raftz

Raft consensus group information (JetStream clustering).
Shows Raft group details:
  • Leader and follower information
  • Log indexes and terms
  • Peer states
  • Stream and consumer assignments

/ipqueuesz

IP-based connection queue statistics.
Monitors connection queues per IP address:
  • 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:
Scrape configuration:

Custom Prometheus Exporter

Poll /varz and /connz:

Security Considerations

1. Restrict Access

Monitoring endpoints expose sensitive information:
Or via configuration:

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.