DEV Community

The Astronomer
The Astronomer

Posted on

Monitoring Docker Containers with Datadog on Ubuntu

I just started monitoring my docker containers running on Ubuntu server. Just in case it helps someone else too, I wanted to share the steps I followed. I will try to walk you through the process of setting up Datadog to monitor your Docker containers on an Ubuntu server, from signing up for a free trial to configuring the Datadog Agent.

1. Sign Up for a Datadog Free Trial

  1. Find Datadog Website: Google the link to sign up for free trial and visit the page.
  2. Sign Up: Click on "Start Free Trial" and fill out the registration form. Follow the prompts to create your brand new account.
  3. Install Agent: After you are signed up, Datadog will provide you with an installation command specific to your account. This command is used to install the Datadog Agent on your Ubuntu server.

2. Install the Datadog Agent on Ubuntu

  1. Run the Installation Command: Datadog will give you a list of options to get installation steps for different kinds of machines. Since we are doing this on Ubuntu machine, choose Ubuntu from the list. There it shows the command that we need. It also has the API Key in it. Copy and paste the installation command provided by Datadog into your terminal where you are logged on to your ubuntu server.

  2. Verify Installation: After running the command, the Datadog Agent should be installed on your server. You can verify this by checking the service status:

   sudo systemctl status datadog-agent
Enter fullscreen mode Exit fullscreen mode

3. Configure Datadog to Monitor Docker Containers

Fun starts now. Datadog should take you to the integration page where you can select and install Docker. Go back to the terminal for now and do step 1 first:

  1. Add dd-agent User to Docker Group: To allow the Datadog Agent to communicate with Docker, you need to add the dd-agent user to the Docker group. Run:
   sudo usermod -a -G docker dd-agent
Enter fullscreen mode Exit fullscreen mode

After running this command, you may need to log out and log back in for the group changes to take effect. I didn't have to do that.

  1. Enable Docker Integration in Datadog:
    • Back to Datadog website: Go to the Datadog Integrations page.
    • Search for docker if not already shown to you: Locate the Docker integration and click "Install". Btw, this will also show you the steps there but I found it really confusing (like I didn't really know where this conf.d folder was located). Hence, I decided to write this article as it might be helpful for others.

Image description

  1. Configure Docker Integration:

    • Edit Configuration File: Open the configuration file for Docker integration. If you go to /etc/datadog-agent/conf.d/docker.d/ on your machine, you may not see the yaml file there. This command will create a new one for you.:
     sudo nano /etc/datadog-agent/conf.d/docker.d/docker_daemon.yaml
    
  • Add Configuration:
    Add the following configuration to the file:

     init_config:
    
     instances:
         - url: "unix://var/run/docker.sock"
    

    This configuration sets the Datadog Agent to connect to the Docker daemon via the Docker socket.

  • Save and Exit: In nano, save changes by pressing CTRL + O, then Enter, and exit with CTRL + X. If you have never used nano before, you can find how to use it by quick Googling. You just need 1 or 2 commands for this though. No need to learn everything.

  1. Restart the Datadog Agent:
    To apply the changes, restart the Datadog Agent service:

    • Stop the Agent: Stop command:
     sudo systemctl stop datadog-agent
    
  • Start the Agent:
    To start the Datadog Agent again, use:

     sudo systemctl start datadog-agent
    
  1. Verify Integration:
    Check the status of the Datadog Agent to ensure that the Docker integration is working correctly:

      sudo datadog-agent status
    

Look for the docker section under Checks to confirm that Docker monitoring is active. Then just go to the dashboard on Datadog website to see the metrics.

Conclusion

By following these steps, you can effectively monitor your Docker containers with Datadog on an Ubuntu server. This setup allows you to gain deep insights into your containerized applications. Now you can quickly respond to any performance issues or anomalies.

Top comments (0)