How to Monitor your AWS EC2/Workspace with Datadog
Tags: datadog, monitoring, devops, aws
Published: 2024-07-08 10:30:19

-1- Log in to your AWS and Datadog accounts. In this example, I will configure AWS Workspace. If you have an EC2 instance, you can follow these steps too. My OS is Ubuntu.

-2-. After deploying an EC2 instance or logging into an AWS Workspace, proceed to update the machine.

-3-. Next, navigate to Datadog → Integrations → Agent → Ubuntu and install the Datadog agent on your host machine. This agent will send metrics to Datadog and does not integrate directly with any AWS services.

-4-. Then click on 'Select API Key,' create a new key, and give it a name. Below that, you will see a command to install the Datadog agent on your system. Copy that command and run it on your server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0ez0wb1qcw9wit4rf59.png)

```
DD_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX DD_SITE="datadoghq.com"  bash -c "$(curl -L https://install.datadoghq.com/scripts/install_script_agent7.sh)"
```

-5-. The command will configure and install the Datadog agent on your machine.

```
sudo usermod -a -G docker dd-agent
systemctl status datadog-agent
datadog-agent version
hostname
```

You can run the above command. Since I have Docker installed on my system, I've added the Datadog agent to the Docker group to monitor Docker. After running the command, check the service status, Datadog version, and finally, the hostname. If you're using an EC2 instance, it will display the instance ID; for a Workspace, it will show the Workspace ID.

-6-. After installing the agent, navigate to your Datadog dashboard, go to 'Infrastructure,' and search for your instance ID or workspace ID. You will now see your host machine on the default dashboard.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7cd6ko7qup6vhpbyeo9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q00wxn3qtkjyt568fyf7.png)

-7-. If you notice, initially, you'll see only a few metrics. However, you can explore other options such as 'Host Info,' 'Containers,' 'Processes,' 'Network,' 'Logs,' and more. By default, you can view host info and metrics on the dashboard. If you want to see 'Processes' and 'Logs,' you'll need to enable them in the Datadog configuration file.

-8-. To enable viewing 'Processes' in the Datadog dashboard, you'll need to edit the configuration file.

```
vi /etc/datadog-agent/datadog.yaml
```

Add the following line to your configuration file to enable 'Processes' monitoring.

```
process_config:
  process_collection:
    enabled: true

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i000mwyzzhmoqwp2cbyx.png)

-9-. After adding the line to the configuration file, restart the Datadog service. Then, navigate to Datadog, click on 'Processes,' and you'll now see the dashboard displaying Processes, PID, total CPU, and RSS memory.

```
sudo systemctl restart datadog-agent
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xcmtfxwc4sxfq03og6p.png)

-10-. Now that Processes are visible, you can expand the dashboard by clicking 'Open in Live Process' on the right-hand side for a larger view. Next, let's configure 'Logs.'

-11-. To configure 'Logs,' uncomment the line 'Logs: true' in the Datadog configuration file.

```
vi /etc/datadog-agent/datadog.yaml
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9muf4ty2vf5x0ce4h78s.png)

-12-. Create a new directory for system logs:

```
sudo mkdir /etc/datadog-agent/conf.d/system_logs.d
```

-13-. Create the conf.yaml file in the new directory:

```
sudo vi /etc/datadog-agent/conf.d/system_logs.d/conf.yaml
```

-14-. Add the log collection configuration to the conf.yaml file:

```
logs:
  - type: file
    path: /var/log/syslog
    service: syslog
    source: syslog
    sourcecategory: system

  - type: file
    path: /var/log/auth.log
    service: auth
    source: auth
    sourcecategory: system

  - type: file
    path: /var/log/kern.log
    service: kernel
    source: kernel
    sourcecategory: system

  - type: file
    path: /var/log/messages
    service: messages
    source: messages
    sourcecategory: system

  # Add other log files as needed
```

-15-. After making the changes, save and exit the file. Typically, you can use 'wq!' to save and exit, but 'x' also works.

-16-. Ensure that the Datadog Agent user has the appropriate permissions to read the log files. Afterward, restart the agent.

```
sudo usermod -a -G adm dd-agent
sudo systemctl restart datadog-agent
```

-17-. Now go to Datadog again and go to "Logs" tab

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf9qet7heahctp2ok5pd.png)

-18-. Finally, with all these different metrics, create a new dashboard and consolidate all windows into one.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4zqeaf3l1411rtv4h5k.png)

-19-. Of course, if you want to monitor additional services or metrics, feel free to explore the official [Datadog website](https://www.datadoghq.com/lpg/?utm_source=advertisement&utm_medium=search&utm_campaign=dg-google-brand-ww&utm_keyword=datadog&utm_matchtype=b&igaag=95325237782&igaat=&igacm=9551169254&igacr=422979063270&igakw=datadog&igamt=b&igant=g&utm_campaignid=9551169254&utm_adgroupid=95325237782&gad_source=1&gclid=CjwKCAjwnK60BhA9EiwAmpHZw5p1f0__jWPvg7LlYYM1AGBF4TxShF7opH80PrQPs62r8fZHnmZX_BoCNC0QAvD_BwE) and refer to the documentation.

-20. In conclusion, this guide has demonstrated how to effectively monitor your AWS EC2 or Workspace using Datadog. We covered installing the Datadog agent, configuring metrics like Processes and Logs, and creating a unified dashboard. It's important to note that Datadog is a paid tool, so if you're practicing as a single user or student, be mindful of potential costs. However, Datadog offers a 14-day trial period, allowing you to explore its features for free during this time. Remember, depending on your specific use case, you can further explore Datadog to unlock additional metrics and services tailored to your needs. For more detailed options, visit the official Datadog website and consult their documentation.