How to Install Datadog Agent with Apache2 on EC2 Ubuntu 22.04

4 min read

This guide shows you how to install Datadog Agent with Apache on EC2 Ubuntu 22.04 and configure it to collect Apache metrics and logs. By the end, you’ll have server status metrics, access logs, and error logs flowing into your Datadog dashboard.

Prerequisites

Install Datadog Agent 7

Datadog provides a one-line install script that sets up Agent 7, creates the dd-agent system user, and configures the service to start on boot.

DD_API_KEY=YOUR_DATADOG_API_KEY DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script_agent7.sh)"

Replace YOUR_DATADOG_API_KEY with your actual API key. If your Datadog account is on a different site (EU, US3, US5, etc.), change DD_SITE accordingly — for example, datadoghq.eu for the EU region.

Once the script finishes, verify the agent is running:

sudo systemctl status datadog-agent

Enable Apache mod_status

Datadog pulls Apache metrics from the mod_status module, which exposes server performance data at a local endpoint. Enable it:

sudo a2enmod status
sudo systemctl reload apache2

Then configure the status endpoint. Edit the status config file:

sudo nano /etc/apache2/mods-enabled/status.conf

Replace the contents with:

<Location "/server-status">
    SetHandler server-status
    Require local
</Location>
ExtendedStatus On
  • Require local — only allows requests from localhost, so the endpoint isn’t exposed to the internet
  • ExtendedStatus On — enables detailed metrics like requests per second, bytes served, and worker status

Reload Apache to apply:

sudo systemctl reload apache2

Test that the endpoint works:

curl http://localhost/server-status?auto

You should see plain-text output with metrics like Total Accesses, BusyWorkers, and IdleWorkers.

Configure the Apache Integration

The Datadog Agent uses YAML config files for each integration. Set up the Apache integration:

sudo cp /etc/datadog-agent/conf.d/apache.d/conf.yaml.example /etc/datadog-agent/conf.d/apache.d/conf.yaml
sudo nano /etc/datadog-agent/conf.d/apache.d/conf.yaml

Replace the contents with:

init_config:

instances:
  - apache_status_url: http://localhost/server-status?auto

logs:
  - type: file
    path: /var/log/apache2/access.log
    service: apache
    source: apache
  - type: file
    path: /var/log/apache2/error.log
    service: apache
    source: apache
  • apache_status_url — points to the mod_status endpoint you enabled earlier
  • logs — tells Datadog to tail the Apache access and error logs
  • source: apache — applies Datadog’s built-in Apache log parsing pipeline automatically

Enable Log Collection

Log collection is disabled by default in the Datadog Agent. Enable it in the main config file:

sudo nano /etc/datadog-agent/datadog.yaml

Find the logs_enabled line (it’s commented out), uncomment it and set it to true:

logs_enabled: true

Fix Log File Permissions

The Datadog Agent runs as the dd-agent user, which doesn’t have access to Apache logs by default. On Ubuntu, Apache logs are owned by root:adm. Add dd-agent to the adm group:

sudo usermod -a -G adm dd-agent

This is the recommended approach — it grants read access to logs without changing file permissions on the log directory.

Restart and Verify

Restart the agent to pick up all the changes:

sudo systemctl restart datadog-agent

Check the integration status:

sudo datadog-agent status

Scroll through the output and look for the Apache section under “Running Checks”. You should see something like:

apache (x.x.x)
---------------
  Instance ID: apache:xxxxxxxxxx [OK]
  Total Runs: 1
  Metric Samples: Last Run: 12, Total: 12
  Events: Last Run: 0, Total: 0
  Service Checks: Last Run: 1, Total: 1

If it shows [OK] with metric samples, the integration is working. Within a few minutes, metrics will appear on the default Apache dashboard in your Datadog console.

Enable the Integration in Datadog

Log into your Datadog console, go to Integrations, search for “Apache”, and click Install Integration. This activates the out-of-the-box Apache dashboard and default monitors. You’ll see metrics like request rate, busy/idle workers, and bytes per request.

Conclusion

You now have Datadog Agent 7 collecting Apache metrics via mod_status and tailing both access and error logs on your EC2 Ubuntu 22.04 instance.

To get more value from your logs, check out How to Parse Custom Logs in Datadog Using Grok Rules for creating custom parsing pipelines. If you’re also running Lambda functions, see Setting Up Datadog Monitoring for Containerized AWS Lambda Functions.