This guide provides step-by-step instructions to set up Nginx monitoring using OpenTelemetry with a separate collector server, sending metrics to Prometheus, and visualizing them in Grafana.
Nginx (Monolithic)
│
├──► OpenTelemetry Collector (Separate Server)
│ ├──► Prometheus (Metrics Storage)
│ ├──► Grafana (Visualization - Dashboard UID: 14282)
SSH into your dedicated OpenTelemetry Collector server and install the OpenTelemetry Collector.
mkdir -p /etc/otel && cd /etc/otel
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-linux-amd64
chmod +x otelcol-linux-amd64
mv otelcol-linux-amd64 /usr/local/bin/otelcol
nano /etc/otel/otel-config.yaml
Add the following:
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"
nginx:
endpoint: "http://your-nginx-server/nginx_status"
exporters:
prometheus:
endpoint: "0.0.0.0:9464"
logging:
loglevel: debug
service:
pipelines:
metrics:
receivers: [nginx]
exporters: [prometheus]
- Replace
your-nginx-server
with the actual IP or hostname of your Nginx server.
otelcol --config /etc/otel/otel-config.yaml > /var/log/otelcol.log 2>&1 &
OR set it as a systemd service:
nano /etc/systemd/system/otel-collector.service
Add:
[Unit]
Description=OpenTelemetry Collector
After=network.target
[Service]
ExecStart=/usr/local/bin/otelcol --config /etc/otel/otel-config.yaml
Restart=always
[Install]
WantedBy=multi-user.target
Enable and start the service:
systemctl daemon-reload
systemctl enable otel-collector
systemctl start otel-collector
On your Nginx server, install the OpenTelemetry module and configure it.
sudo apt-get install nginx-opentelemetry-module
nano /etc/nginx/nginx.conf
Add:
load_module modules/ngx_http_opentelemetry_module.so;
http {
opentelemetry_config /etc/nginx/otel.yaml;
server {
listen 80;
location / {
opentelemetry_trace_context;
}
}
}
nano /etc/nginx/otel.yaml
Add:
collector_endpoint: "http://otel-collector-server:4317"
service_name: "nginx-monolith"
sample_rate: 1.0
- Replace
otel-collector-server
with the IP/hostname of your OpenTelemetry Collector server.
systemctl restart nginx
Now, on your Prometheus server, edit the prometheus.yml
file.
nano /etc/prometheus/prometheus.yml
Add:
scrape_configs:
- job_name: 'otel-nginx'
static_configs:
- targets: ['otel-collector-server:9464']
Replace otel-collector-server
with the actual IP of your OpenTelemetry Collector server.
Restart Prometheus:
systemctl restart prometheus
Now that OpenTelemetry is collecting metrics and sending them to Prometheus, visualize them in Grafana.
- Open Grafana → Dashboards → Import.
- Enter UID:
14282
(Pre-built OpenTelemetry Dashboard). - Select Prometheus as the data source.
- Click Import.
On the OpenTelemetry Collector server, run:
curl http://localhost:9464/metrics | grep nginx
Expected output:
otel_http_server_duration_seconds{host="nginx-monolith"} 0.5
otel_http_server_errors_total{host="nginx-monolith", status="500"} 2
- Open Prometheus UI:
http://prometheus-server:9090
- Run a query for:
otel_http_server_duration_seconds
- Open Grafana.
- Check if Dashboard UID
14282
is showing real-time Nginx metrics.
Metric | Description |
---|---|
otel_http_server_duration_seconds |
Time taken to process HTTP requests |
otel_http_server_errors_total |
Count of HTTP errors (4xx, 5xx) |
otel_http_upstream_latency_seconds |
Latency in responses from upstream servers |
otel_http_request_size_bytes |
Size of incoming HTTP requests |
otel_http_response_size_bytes |
Size of outgoing responses |
otel_http_request_count_total |
Total number of processed requests |
nginx_active_connections |
Number of active client connections |
nginx_waiting_connections |
Number of idle client connections |
otel_trace_id |
Unique trace ID for distributed tracing |
-
Run:
curl http://otel-collector-server:9464/metrics | grep nginx
If output appears, OpenTelemetry is correctly collecting Nginx metrics.
-
Check Prometheus (
http://prometheus-server:9090
) forotel_http_server_duration_seconds
. -
Go to Grafana and view Dashboard UID
14282
for real-time Nginx metrics.
With this setup, you now have:
- OpenTelemetry Collector (separate server) collecting Nginx metrics
- Prometheus storing metrics
- Grafana visualizing them (Dashboard UID
14282
) - Distributed tracing, structured logs, and advanced monitoring
🚀 Enjoy powerful Nginx monitoring with OpenTelemetry! 🚀