Forem

Datadog Agent Installation on AWS EC2 (Linux Server) and Sending Logs to Datadog Cloud

Datadog Agent Installation on AWS EC2 (Linux Server) and Sending Logs to Datadog Cloud


1.Prerequisites

  • An active Datadog account (https://app.datadoghq.com)
  • A running AWS EC2 instance (Amazon Linux, Ubuntu, or other Linux distribution)
  • Root or sudo access to the EC2 instance
  • Your Datadog API key (found under Integrations → APIs in the Datadog dashboard)

2.Connect to Your EC2 Instance
Use SSH to connect:

ssh -i /path/to/your-key.pem ec2-user@


3.Install the Datadog Agent
For Amazon Linux or RHEL-based systems
DD_API_KEY= DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

For Ubuntu or Debian-based systems

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


4.Enable and Start the Agent

sudo systemctl enable datadog-agent
sudo systemctl start datadog-agent

Check the agent status:

sudo datadog-agent status


5.Enable Log Collection

Edit the Datadog Agent configuration file:

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

Uncomment and set:

logs_enabled: true

Save and exit, then restart the agent:

sudo systemctl restart datadog-agent


6.Configure Log Sources

To send specific logs (e.g., application logs), create a configuration file under:

/etc/datadog-agent/conf.d/.d/conf.yaml

Example for an Nginx log:

logs:
  - type: file
    path: /var/log/nginx/access.log
    service: nginx
    source: nginx

Enter fullscreen mode Exit fullscreen mode

Restart the agent again:

sudo systemctl restart datadog-agent


7.Verify Logs in Datadog

  • Go to Logs → Live Tail in the Datadog dashboard.
  • You should see logs streaming from your EC2 instance.
  • Use filters like service:nginx or host: to refine results.

8.Optional: Tagging and Metadata

You can add tags to your EC2 instance for better organization:

sudo sh -c 'echo "tags: environment:production,team:devops" >> /etc/datadog-agent/datadog.yaml'
sudo systemctl restart datadog-agent


9.Troubleshooting

Check agent logs:
sudo tail -f /var/log/datadog/agent.log
Ensure outbound traffic to Datadog endpoints is allowed (port 443).
Verify your API key and region are correct.


Final Result:
Your AWS EC2 instance is now sending system metrics and logs to Datadog Cloud for monitoring and analysis.

Top comments (0)