stub_status metrics (active connections, requests, reading/writing/waiting). You will need a Datadog account and an API key to follow along.
Sign up for a Datadog trial account if you don’t have one. During onboarding, copy the one-line agent install command and your API key — you’ll use them on your EC2 host.
Prerequisites
- Ubuntu/Debian EC2 instance with sudo access.
- NGINX installed and running on the instance.
- Datadog account and API key.
- Basic familiarity with editing NGINX configuration files and reloading the service.
1. Install the Datadog Agent
From the Datadog web UI choose the correct OS (Ubuntu/Debian) and copy the one-line install command. Replace<YOUR_API_KEY> with your Datadog API key and set DD_SITE to the appropriate Datadog site (for example, datadoghq.eu for the EU region). Example command:
- Add the Datadog apt repository and import signing keys.
- Install the
datadog-agentpackage. - Start the Datadog Agent service.


2. Enable the NGINX integration (stub_status)
Datadog needs a locally reachable NGINXstub_status endpoint to collect NGINX metrics. The safest approach is to expose this endpoint only to localhost, so the agent (running on the same host) can scrape it while external access remains blocked.
Go to Datadog → Integrations → Integrations and search for “NGINX”. Datadog may autodetect NGINX on your host.

- Verify your NGINX has the
stub_statusmodule:
http_stub_status_module, the module is present.
- Configure NGINX to expose
stub_statusonlocalhost. A common pattern is to listen on127.0.0.1:81and restrict access to the loopback interface. Add a server block (for example in/etc/nginx/sites-available/example-httpsor another site file):
- Listens on
127.0.0.1:81so only the local host can connect. - Turns off access logging for the endpoint to prevent log growth from frequent scraping.
- Allows only
127.0.0.1and denies all other addresses.
- Test and reload NGINX:
- Verify the endpoint from the host itself (run on the server):
- If you fetch the endpoint from a remote machine you should either receive a
403 Forbidden(if bound to 0.0.0.0 but access denied) or a connection error likeconnection refused(if bound to loopback only). Both outcomes are normal depending on your binding configuration. - In Datadog’s NGINX integration settings, use
localhostand the port you configured (for example,81) if it requests a host/port.
stub_status location inside an existing HTTPS server block, ensure you include allow 127.0.0.1; deny all; and access_log off; inside that location /nginx_status so only the local agent can access it:
stub_status endpoint and start reporting NGINX metrics.
3. Datadog dashboards and host view
Once the integration is configured and the agent collectsstub_status, Datadog will populate or create NGINX dashboards. Navigate to Dashboards → All Dashboards to find NGINX-related dashboards.



- Bookmark dashboards you use often.
- Create monitors/alerts for CPU, memory, disk I/O, or NGINX-specific metrics (active connections, request rates).
- Run load tests (for example
ab,wrk) to generate traffic and observe behavior.
Quick reference — useful commands & checks
Troubleshooting checklist
- Ensure the Datadog Agent is running:
sudo systemctl status datadog-agent. - Confirm the
nginx_statusendpoint is reachable from the host:curl http://127.0.0.1:81/nginx_status. - If Datadog reports no NGINX metrics:
- Verify the NGINX integration is enabled in Datadog and the host/port configured in the integration matches your setup (e.g.,
localhost:81). - Check the agent logs for errors:
sudo journalctl -u datadog-agent -f(or review/var/log/datadog/).
- Verify the NGINX integration is enabled in Datadog and the host/port configured in the integration matches your setup (e.g.,
- Keep the
stub_statusendpoint bound tolocalhostor explicitly deny external access to avoid exposing internal server state.
Links and references
- Datadog Agent installation documentation
- Datadog NGINX integration docs
- NGINX stub_status module documentation