Skip to main content

NGINX

Overview

This guide will walk you through collecting rich telemetry data from your nginx server using nginx-module-otel module and we'll use prometheus nginx exporter to collect metrics.

Prerequisties

  • NGINX Server installed.

Collecting metrics

Step 1: expose stub_status metrics from nginx

In your Nginx config add the following config

server {
listen 80;
server_name localhost;

location /status {
stub_status;
allow 127.0.0.1;
deny all;
}
}

Step 2: Run the nginx prometheus exporter using docker

docker run --network=host nginx/nginx-prometheus-exporter:1.4.2 \
--nginx.scrape-uri=http://localhost/status

Step 3: Add the following receiver in your Scout collect

 prometheus/nginx:
config:
scrape_configs:
- job_name: nginx
scrape_interval: 5s
metrics_path: /metrics
static_configs:
- targets: ['0.0.0.0:9113']

Note: Make sure you use in the pipelines as well.

Great work, Now the metrics are scraped from the nginx

Collecting traces

Step 1: Add the nginx repositoring

Install the prerequisites:

sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Verify that the downloaded file contains the proper key:

gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

To set up the apt repository for stable nginx packages, run the following command:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

Step 2: Installing Otel module for nginx

sudo yum install nginx-module-otel

Step 3: Configure nginx to send traces

Add the following configs in your nginx.conf file:

load_module modules/ngx_otel_module.so;

http {
otel_exporter {
endpoint 0.0.0.0:4317;
}
otel_service_name nginx;
otel_resource_attr environment <deployment-environment>;
otel_trace on;
otel_trace_context inject;
}

Note: replace otel_service_name and otel_resource_attr with actual values.

Now the traces will be sent to the otel collector.

Collecting logs

Step 1: Add the filelog receiver to collect the logs

receivers:
filelog:
include:
- /var/log/nginx/*.log
start_at: beginning

Note: If you have configure log collection location to custom directory, update the include block with the correct path.

Great work. Now we have successfully implemented nginx with OpenTelemetry instrumentation