Integration with NATS
This guide explains how to monitor NATS using the OpenTelemetry Collector (otelcol
) and export both logs and metrics to OpenObserve for visualization.
Overview
NATS is a high-performance, cloud-native messaging system widely used in microservices, IoT, and distributed applications. Monitoring NATS is critical to ensure seamless communication, security, and performance. With OpenTelemetry and OpenObserve, you gain real-time visibility into NATS logs, message throughput, errors, and system resource usage.
Steps to Integrate
Prerequisites
- Docker installed
- OpenObserve account (Cloud or Self-Hosted)
- Basic understanding of Prometheus exporters
Step 1: Install NATS
-
Install dependencies:
-
Download and install NATS server:
-
Start NATS with JetStream enabled:
Step 2: Configure NATS Logging and Metrics
-
Create a configuration file:
Add:
-
Start NATS with config file:
-
Verify logs:
-
Start NATS Prometheus exporter:
docker run -p 7777:7777 natsio/prometheus-nats-exporter:latest \ -D -jsz=all -accstatz -connz_detailed -gatewayz -healthz \ -connz -varz -subz \ http://<NATS_SERVER_IP>:8222
Metrics are now exposed on port
7777
.
Step 3: Install OpenTelemetry Collector
Download and install the latest otelcol-contrib.
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.116.1/otelcol-contrib_0.116.1_linux_amd64.deb
sudo dpkg -i otelcol-contrib_0.116.1_linux_amd64.deb
Note: Replace version numbers in download links if a newer release is available. Always check the GitHub Releases page.
Step 4: Configure OpenTelemetry Collector
-
Edit config file:
-
Add configuration:
receivers: filelog/std: include: [ /var/log/nats-server.log ] start_at: beginning prometheus: config: scrape_configs: - job_name: 'nats' scrape_interval: 5s static_configs: - targets: ['localhost:7777'] processors: batch: timeout: 5s exporters: otlphttp/openobserve: endpoint: OPENOBSERVE_ENDPOINT headers: Authorization: "OPENOBSERVE_TOKEN" stream-name: nats service: pipelines: metrics: receivers: [prometheus] processors: [batch] exporters: [otlphttp/openobserve] logs: receivers: [filelog/std] processors: [batch] exporters: [otlphttp/openobserve]
Replace placeholders:
OPENOBSERVE_ENDPOINT
→ API endpoint (e.g.,https://api.openobserve.ai
)OPENOBSERVE_TOKEN
→ Access token from data sources page
Step 5: Restart OpenTelemetry Collector
Check logs to verify NATS logs and metrics are flowing.
Step 6: Load Testing NATS (Optional)
Use nats bench
to generate load:
In Terminal 1:


Step 7: Visualize in OpenObserve
- Log in to OpenObserve and explore the NATS stream under Logs.
- Explore the NATS stream under Metrics.
Tip
You can use preconfigured Dashboard in OpenObserve to to visualize real-time logs and metrics.
Troubleshooting
-
No Logs in OpenObserve
- Ensure
filelog
receiver points to/var/log/nats-server.log
. - Verify OpenTelemetry Collector is running with correct config.
- Ensure
-
Metrics Not Visible
- Check that Prometheus exporter is running on
localhost:7777
. - Confirm scrape target matches the exporter port.
- Check that Prometheus exporter is running on
-
Collector Fails to Start
-
Check config file syntax with: