Monitoring nginx with Datadog - Metrics, Logs, and Traces
nginx monitoring is built from a combination of metrics that the Agent reads from a status page, logs sent from files, and traces created by a module. The endpoint the Agent reads changes depending on whether you run NGINX Open Source or NGINX Plus, and linking IDs in a pipeline lets you move back and forth between logs and traces.
There Are Four Paths Available for nginx Monitoring
The data that reaches Datadog from nginx splits into four paths depending on where you enable it. The Agent's nginx check reads a status page that nginx exposes itself and turns it into metrics. In NGINX Open Source this status page is created by the stub_status module, and in the commercial NGINX Plus the Plus API takes that role. Logs travel on a path separate from the status page: the Agent reads the access log and error log files and sends them. Traces are separate again; they are created by having nginx itself load an nginx module distributed by Datadog (as of October 2026; source: Nginx).
| Path | Where to enable it | What you can see | Questions it answers easily |
|---|---|---|---|
| stub_status metrics | nginx's status.conf and the Agent's nginx.d/conf.yaml | Total requests, connections (accepted / handled / active), reading / writing / waiting | How many connections it is handling right now |
| NGINX Plus API | /api with http_api_module, and use_plus_api | 4xx / 5xx counts, upstream status, cache, SSL handshakes | At which layer errors increased |
| Access logs and error logs | logs_enabled in datadog.yaml and logs in nginx.d/conf.yaml | One line per request | Which requests failed |
| Tracing module | load_module in nginx.conf | A span per request | Where requests passing through the proxy spent their time |
The top two rows of the table are values that count totals for the whole server, not records of individual requests. Conversely, logs and traces are per-request records, so when you look at overall trends you aggregate them. As one way to proceed, first add the status page metrics and the access logs to cover both the overall picture and individual requests, and add the module when you want to trace the breakdown of slowness; this lets you split the nginx configuration changes into two rounds. Installing the Agent itself is summarized in installing the Agent on Linux.
Open stub_status and Tell the Agent the Status Page URL
First check whether http_stub_status_module appears in the output of nginx -V. According to the official nginx documentation, this module is not included in the default build and is built in with --with-http_stub_status_module. If it is there, place a status.conf in a location such as /etc/nginx/conf.d/ (as of October 2026; source: Nginx).
server {
listen 81;
server_name localhost;
access_log off;
allow 127.0.0.1;
deny all;
location /nginx_status {
stub_status;
server_tokens on;
}
}| Item | Description in the official nginx documentation |
|---|---|
| Active connections | The current number of active client connections, including waiting connections |
| accepts | The total number of accepted client connections |
| handled | The total number of handled connections, the same value as accepts unless a limit such as worker_connections has been reached |
| requests | The total number of client requests |
| Reading | The number of connections where the request header is being read |
| Writing | The number of connections where the response is being written back to the client |
| Waiting | The number of idle connections waiting for the next request |
allow and deny are directives of nginx's ngx_http_access_module; the rules are checked in order from the top, and the first match is used (source: Module ngx_http_access_module). With this status.conf, only requests from 127.0.0.1 reach the status page, and everything else is refused by deny all. On the nginx side, it is enough to check the configuration with nginx -t and then reload with nginx -s reload; a full restart is not needed. On the Agent side, write http://localhost:81/nginx_status/ in nginx_status_url in nginx.d/conf.yaml and restart. The minimum is Agent 6.0.0 (source: Nginx).
With NGINX Plus, the Endpoint the Agent Reads Changes at Release 13
stub_status also works with NGINX Plus, but it provides fewer metrics, so Datadog recommends the Plus-side mechanism. The dividing line for Plus is release 13. Packages before 13 include the status module, and from 13 on the status module is deprecated and you need to use the Plus API (as of October 2026; source: Nginx).
| Release | nginx side | Agent side (nginx.d/conf.yaml) |
|---|---|---|
| Before 13 | Write status in a location in status.conf | The status page URL in nginx_status_url |
| 13 or later | Open an /api location with http_api_module (the example uses listen 8080 and api write=on) | use_plus_api: true and an nginx_status_url pointing to /api |
| stream statistics on 13 or later | No additional work | Collected by default; to stop, set use_plus_api_stream: false |
The same page also has a statement that places the deprecation at release 15 and later, but the Agent-side use_plus_api is meant for 13 and later. Add status_zone to server blocks for which you want to collect even per-second counts by response code. What Plus adds are 4xx and 5xx counts, upstream server connection counts, 5xx, and health checks, cache hits, and the success or failure of SSL handshakes. Because upstream 5xx can be collected separately from overall errors, during an incident you can look at the state of the backend servers from nginx's metrics. The NGINX Open Source status page has no counts by response code, so count the error rate from the status codes in the access log.
For nginx in Containers, Write the Same URL in Labels or Annotations
When nginx runs in a container, the values you give the Agent are the same three as on a host (check name nginx / empty init_config / nginx_status_url); only where you write them changes. The official documentation treats this as an Autodiscovery configuration template and shows it in a form written in labels or annotations. In every container example, %%host%% sits in the host name position of the URL.
| Environment | Metrics configuration | Log configuration |
|---|---|---|
| Host | instances in nginx.d/conf.yaml | logs in the same file |
| Docker | The Docker label com.datadoghq.ad.instances and two others | The Docker label com.datadoghq.ad.logs |
| Kubernetes | The Pod annotation ad.datadoghq.com/nginx.checks (the form for Agent v7.36 and later) or a DatadogInstrumentation resource | The Pod annotation ad.datadoghq.com/nginx.logs |
| ECS | dockerLabels in the task definition | com.datadoghq.ad.logs in the same dockerLabels |
For Kubernetes, there is an example that puts status.conf in a ConfigMap, mounts it in nginx's configuration directory, and exposes port 81 as a containerPort in the Pod. What to watch when copying is the port number: in the Kubernetes section of the official documentation, the example in the parameter table is 18080, while the annotation example is 81. Whichever you copy, align it with the listen number in your own status.conf. The Docker, ECS, and Kubernetes DatadogInstrumentation examples carry a note that they are forms that work only with NGINX Open Source; for Plus, write in the configuration from the previous section as is (source: Nginx).
| Item | Host example | Kubernetes example |
|---|---|---|
allow / deny | allow 127.0.0.1 and deny all | Not present |
| How the status page is written | stub_status | stub_status on (according to the official nginx documentation, the form with an argument that was required before 1.7.5) |
| Locations other than the status page | Not defined | Return 404 with location / |
In containers, the Agent connects from a different container and the source is not 127.0.0.1, so if you copy the host example's allow and deny, requests to the status page hit deny all. As in the official Kubernetes example, leave out allow / deny and align on the form in the example in which the 404 from location / keeps anything other than the status page from being returned. Even when you write the log configuration in labels or annotations, it assumes that log collection is enabled on each platform.
nginx's Default Log Format Does Not Include Response Time
Logs are not collected under the Agent's default settings, so set logs_enabled: true in datadog.yaml and add a logs item to nginx.d/conf.yaml. The official example reads two files, /var/log/nginx/access.log and /var/log/nginx/error.log, with type: file. Both carry service: nginx and source: nginx. The official documentation includes an example that adds $request_time to log_format inside http in /etc/nginx/nginx.conf (as of October 2026; source: Nginx).
| What to touch | What to write |
|---|---|
The log_format line | Define a format that includes $request_time and give it a name (the name in the official example is nginx) |
The access_log line | After the file path, write the name of that format |
What $request_time contains | The seconds from reading the first byte from the client until the last byte is sent and the log is written (with millisecond resolution) |
The example in the official documentation puts the line access_log /var/log/nginx/access.log; below the log_format nginx definition. Under the nginx specification, if access_log has no format name, the predefined combined format is used (source: Module ngx_http_log_module). When copying it, adding nginx to the end of the access_log line makes the log written in the format you defined. Breaking the lines apart after they arrive is the job of processors, and the ingestion settings in general and the order of checks when logs do not arrive are summarized in setting up log collection.
For Traces, Have nginx Load a Module, and Link It to Logs by ID
ngx_http_datadog_module.so, which Datadog distributes in the nginx-datadog releases on GitHub, is the module that creates nginx traces. Extract it from the tarball that matches your nginx version and CPU type, and place it in a location such as /usr/lib/nginx/modules, which the official documentation lists. When you load it at the very top of the configuration, by default it connects to the local Agent and creates traces for every location. Change the service name and the sampling rate with the datadog_* directives (as of October 2026; source: Instrumenting NGINX).
load_module modules/ngx_http_datadog_module.so;
http {
datadog_service_name my-nginx;
datadog_sample_rate 0.1;
}- Add $datadog_trace_id and $datadog_span_id to log_format and reload nginx
- On the log configuration screen, clone the nginx pipeline you use
- Add a Grok Parser to the cloned pipeline and extract dd.trace_id and dd.span_id
- Specify dd.trace_id in the Trace ID Remapper and dd.span_id in the Span ID Remapper
- Save and enable the pipeline; newly arriving logs will be linked
Once traces and logs are linked, you can move from a slow trace to the access log for the same request, and from an error line to its trace. The effort lies in the ID format: the IDs written to the log are hexadecimal, so they need to be converted to decimal inside the log pipeline. Extraction takes a single Grok Parser rule, and the official documentation shows how to write it so that the - of requests that were not traced is treated as empty. How to instrument the Kubernetes Ingress-NGINX Controller is split on the same page into sections for each Controller version.
The First Monitor for nginx Monitoring Starts with nginx.can_connect
If nginx is listed in the Checks section of the status output, the configuration is working. On Linux, run sudo datadog-agent status; in containers, run agent status in the Agent container (source: Agent Commands). The nginx check has the service checknginx.can_connect, which returns CRITICAL if the Agent cannot collect metrics from nginx. This check includes no events, so as one way to proceed, make your first monitor one that catches this CRITICAL, and then add one that watches for sudden changes in nginx.net.request_per_s. List the servers and containers running nginx, and note on each row whether it is NGINX Open Source or Plus, and for Plus, the release number. Route the Plus rows to the table in the Plus section, and the container rows to the section on labels and annotations.