Skip to main content
In this lesson you’ll install the Datadog Agent on an Ubuntu EC2 instance and enable Datadog’s NGINX integration so the agent can collect system metrics (CPU, memory, disk I/O, network) and NGINX 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:
Run that command on your EC2 instance. The installer will:
  • Add the Datadog apt repository and import signing keys.
  • Install the datadog-agent package.
  • Start the Datadog Agent service.
Example excerpt from a successful install:
The install can take a few minutes. After completion, Datadog will begin reporting the host to the Datadog web app. Visit Datadog → Dashboards → Hosts to see your host and system metrics.
A Datadog dashboard screenshot titled "System - Disk I/O" displaying multiple time-series charts (I/O wait, disk latency, disk read/write rates, read/write requests, and disk CPU utilization) with small spikes around 12:15. The Datadog left sidebar and top navigation bar are also visible.
You should begin to see system metrics (CPU, memory, disk I/O, network, etc.) appear in Datadog.
A screenshot of a Datadog monitoring dashboard showing system metrics panels (system load, CPU usage, I/O wait, system memory, and network traffic) with small line graphs. The left side has a navigation sidebar and the top bar contains time-range controls and action buttons like Share and Clone.

2. Enable the NGINX integration (stub_status)

Datadog needs a locally reachable NGINX stub_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.
A screenshot of the Datadog Integrations page showing autodetected integrations (Nginx and SSH) at the top and a grid of available integration tiles (e.g., .NET, 1Password, Active Directory, Ably) below. The Datadog sidebar navigation and search/filter bar are also visible.
Follow these steps to enable and configure the integration:
  1. Verify your NGINX has the stub_status module:
If the output includes http_stub_status_module, the module is present.
  1. Configure NGINX to expose stub_status on localhost. A common pattern is to listen on 127.0.0.1:81 and restrict access to the loopback interface. Add a server block (for example in /etc/nginx/sites-available/example-https or another site file):
This configuration:
  • Listens on 127.0.0.1:81 so 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.1 and denies all other addresses.
  1. Test and reload NGINX:
  1. Verify the endpoint from the host itself (run on the server):
Example expected output:
Notes:
  • 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 like connection refused (if bound to loopback only). Both outcomes are normal depending on your binding configuration.
  • In Datadog’s NGINX integration settings, use localhost and the port you configured (for example, 81) if it requests a host/port.
If you prefer to place the 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:
After reloading NGINX, Datadog’s agent should be able to scrape the stub_status endpoint and start reporting NGINX metrics.

3. Datadog dashboards and host view

Once the integration is configured and the agent collects stub_status, Datadog will populate or create NGINX dashboards. Navigate to Dashboards → All Dashboards to find NGINX-related dashboards.
A screenshot of the Datadog web app displaying an "All Dashboards" list with various dashboard names and a purple banner that reads "Organize Dashboards with Lists." The left sidebar shows navigation items like Dashboards, Monitors, and Integrations.
Open the “NGINX - Overview” dashboard (it may take a few minutes for metrics to appear). Adjust the time range (for example, last 15 minutes) to see recent activity.
A screenshot of the Datadog web app showing an "NGINX - Overview" dashboard. It displays a large green NGINX banner, activity summary panels on the right, and sections for alerts and anomaly detection below.
If you still see “no data”, verify the agent and integration settings. You can view the specific host under Datadog’s Hosts or via the Integrations host list to check system metrics and the host map.
A screenshot of the Datadog web UI showing a Host Map for a single "nginx" host, displayed as a green hexagon. The host details list components like "agent" and "ntp" and show system/metrics panels on the page.
From the host and dashboard views you can:
  • 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_status endpoint 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/).
  • Keep the stub_status endpoint bound to localhost or explicitly deny external access to avoid exposing internal server state.
That completes the Datadog Agent install and NGINX integration setup. In future lessons we’ll cover advanced performance troubleshooting for NGINX and configuring Datadog monitors/alerts.

Watch Video