This guide provides complete setup instructions for monitoring self-hosted NGINX with OpenTelemetry. Follow these steps to configure your NGINX server, OpenTelemetry Collector, and New Relic integration.
If any verification step fails, install the missing components before continuing. Need help installing the Collector? Check the OpenTelemetry Collector installation guide.
Step 1: Configure NGINX stub status
Configure the stub_status module to expose metrics from your NGINX server. This module provides basic performance statistics that OpenTelemetry will collect.
Add this configuration to your NGINX config file (/etc/nginx/nginx.conf):
server{
listen8080;
server_name localhost;
location /nginx_status{
stub_statuson;
access_logoff;# Don't log monitoring requests
allow 127.0.0.1;# Only allow localhost access
allow ::1;# Allow IPv6 localhost
deny all;# Deny all other access
}
}
Test your NGINX configuration:
bash
$
sudo nginx -t
If the test passes, reload NGINX:
bash
$
sudo nginx -s reload
Test the endpoint:
bash
$
curl http://127.0.0.1:8080/nginx_status
Expected output:
Active connections: 1
server accepts handled requests
16 16 16
Reading: 0 Writing: 1 Waiting: 0
Test the HTTP response:
bash
$
curl-I http://127.0.0.1:8080/nginx_status
Expected output: Should start with HTTP/1.1 200 OK
Step 2: Configure the OpenTelemetry Collector
Configure the OpenTelemetry Collector to scrape metrics from your NGINX stub status endpoint and send them to New Relic.
The OpenTelemetry Collector uses three main components for NGINX monitoring:
Receivers - Connect to your NGINX stub status endpoint to collect metrics
Processors - Add server identification and batch metrics for efficient transmission
Exporters - Send the processed metrics to your New Relic account via OTLP HTTP
Before editing the configuration, you'll need two key pieces of information:
Your stub status URL - From Step 1 (default: http://127.0.0.1:8080/nginx_status)
A unique deployment name - Choose a name that identifies this specific NGINX server (e.g., production-web-01, staging-api, prod-lb-01)
The deployment name will appear in New Relic dashboards and helps you identify specific servers when you have multiple NGINX instances.
重要
Before editing: Back up your existing configuration: sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backup
Edit your Collector configuration file (typically /etc/otelcol-contrib/config.yaml) and add the following sections. If you already have receivers, processors, or exporters sections, merge these with your existing configuration:
1. Configure the NGINX receiver:
receivers:
nginx:
endpoint: http://127.0.0.1:8080/nginx_status # Replace with your stub status URL
collection_interval: 30s # How often to collect metrics
metrics:
nginx.requests:
enabled:true
nginx.connections_accepted:
enabled:true
nginx.connections_handled:
enabled:true
nginx.connections_current:
enabled:true
2. Configure processors for metadata and batching:
processors:
# Detect system information (hostname, etc.)
resourcedetection:
detectors:[system]
system:
resource_attributes:
host.name:
enabled:true
host.id:
enabled:true
# Add NGINX-specific identification
resource:
attributes:
-key: nginx.server.endpoint
value:"http://127.0.0.1:8080/nginx_status"# Replace with your endpoint
action: upsert
-key: nginx.deployment.name
value:"production-web-01"# Replace with your server name
action: upsert
# Batch metrics for efficient sending
batch:
timeout: 30s
send_batch_size:1024
# Transform metrics for better display in New Relic
transform/nginx_metrics:
metric_statements:
-context: resource
statements:
# Customize the display name as needed for your New Relic dashboard
Endpoint URL: Change http://127.0.0.1:8080/nginx_status to match your stub status configuration from Step 1
Deployment name: Replace production-web-01 with a unique identifier for this NGINX server
Choosing a good deployment name:
Use descriptive names like production-web-01, staging-api, or prod-lb-01
Must be unique across all NGINX servers within your New Relic account
This name will appear in dashboards and help you identify specific servers
Keep it short but meaningful for easy filtering and alerting
Step 3: Set up authentication
Configure secure authentication so the OpenTelemetry Collector can send data to your New Relic account. This step sets up environment variables to keep your credentials secure.
Before configuring authentication, gather these two pieces of information:
Your OTLP Endpoint:
Use the appropriate endpoint for your New Relic region. See Configure endpoint, port, and protocol for the complete list of endpoints and supported ports for your region.
For example:
Replace https://otlp.nr-data.net:4318 with your region's endpoint
Replace YOUR_LICENSE_KEY_HERE with your actual license key from above
Step 4: Start monitoring
Now that everything is configured, start the OpenTelemetry Collector and verify that data is flowing to New Relic.
Apply the configuration changes:
bash
$
sudo systemctl daemon-reload
$
sudo systemctl restart otelcol-contrib.service
Verify the service is running:
bash
$
sudo systemctl status otelcol-contrib.service
Expected output: Active: active (running) with no recent errors
Check startup logs:
bash
$
sudo journalctl -u otelcol-contrib.service -n20
Look for these success indicators:
✅ "Everything is ready. Begin running and processing data."
✅ "Scraping metrics" - Successfully collecting from NGINX
✅ "Exporting metrics" - Successfully sending to New Relic
Generate test traffic (to create metrics):
bash
$
# Make a few requests to your NGINX server
$
curl http://localhost
Allow time for initial data to appear in New Relic, then access your NGINX dashboard to verify data collection.
Step 5: (Optional) Forward NGINX logs
In addition to metrics, you can send NGINX access and error logs to New Relic for comprehensive monitoring and troubleshooting. These logs complement the core NGINX metrics and provide detailed request-level insights.
ヒント
Skip this step if: You only need basic NGINX metrics and don't require detailed request logs.
First, configure NGINX to output JSON-formatted logs that are easier to parse and query.
Add this to your NGINX configuration (/etc/nginx/nginx.conf):
YAML syntax errors - Fix indentation and syntax issues
Missing environment variables - Verify credentials are set in environment file
File permission issues - Run sudo chown otelcol-contrib:otelcol-contrib /etc/otelcol-contrib/config.yaml
Invalid endpoint URLs - Check NGINX endpoint and New Relic OTLP endpoint
Missing component configurations - Ensure all receivers, processors, and exporters referenced in the service pipelines section are actually defined in their respective configuration sections above
Restart after fixes:
bash
$
sudo systemctl restart otelcol-contrib.service
Step-by-step diagnosis:
Verify NGINX stub status works:
bash
$
curl http://127.0.0.1:8080/nginx_status
Should return connection statistics.
Check Collector is running and healthy:
bash
$
sudo systemctl status otelcol-contrib.service
$
sudo journalctl -u otelcol-contrib -n20
The logs will provide detailed context if there are any configuration or runtime issues with the OpenTelemetry Collector.
Check for data with NRQL:
FROM Metric SELECT*WHERE nginx.deployment.name LIKE'%production%'LIMIT1