Monitor your server and Docker containers with Datadog for free

Mathieu Androz
3 min readJun 3, 2021

--

If you have a bare metal server, VPS, single instance from any web hoster, you certainly need to monitor your machine.
Datadog is a pretty good, powerful service to monitor your servers and applications. It provides visualization of resources, logs, APM, configuration of alarms and more.
Gracefully, Datadog offers a free infrastucture service monitoring which is pretty cool if you have a little server for personal use.

In this article, I will show you how to configure datadog agent in a single server, to monitor server resources and containers running on it.

Prerequisites

  • Having a Datadog account
  • Knowing your Datadog API key
  • Having docker containers to monitor
  • Having docker and docker-compose installed on your server

Deployment of Datadog agent

As we want to monitor our server and its containers, we will deploy Datadog agent as a container in a specific network.

To deploy it, this is pretty simple :
- Copy/paste this docker-compose.ymlfile on your server;
- SetDD_KEY= with your Datadog API key;
- Set DD_HOSTNAME with your server name or the name you want to be associated to the server;

If you want further informations about different existing envvars, you can take a look at the documentation :).

The docker-compose file is now ready ! Start the Datadog agent with the following command line from the folder containing the docker-compose.yml file :

user@myserver:/opt/datadog$ ls 
docker-compose.yml
user@myserver:/opt/datadog$ docker-compose up -d

Autodiscovery of your docker containers/apps

The Datadog agent is now up and running, and able to discover new containers.

In docker-compose files of your applications, you need to add some labels to configure logs parser, service tag, environment and version.

Configuration of integration with Autodiscovery

labels:
com.datadoghq.ad.check_names: '[<INTEGRATION_NAME>]'
com.datadoghq.ad.init_configs: '[{}]'
com.datadoghq.ad.instances: '[{"host":"%%host%%","port":"%%port%%"}]'

Those 3 labels are required to configure an integration with Autodiscovery. See the documentation for more informations :)

Configuration of logs integration with Autodiscovery

The following label is used to activation log collection :

labels:
com.datadoghq.ad.logs: '[{"source":"go", "service":"go"}]'

Configuration of tags with Autodiscovery

Tags are used to identify different services in APM.

labels:
com.datadoghq.tags.env: 'prod'
com.datadoghq.tags.service: 'myapp'
com.datadoghq.tags.version: '<VERSION>'

tags.env : used to make difference between different environments and not mixing data/metrics for a same service.

tags.service : Define the name of the service in APM

tags.version : Define the version of your application in service APM view.

For more informations, take a look at the documentation :).

Screenshot of Datadog’s containers view
Datadog’s containers view
Screenshot of Datadog’s APM service view
Datadog’s APM service view with container details

You are now ready to monitor your Docker infrastructure for free with Datadog, with pretty cool dashboards, logs, infrastructure metrics and APM metrics !

I hope you’ll enjoy reading this article :)

--

--

Mathieu Androz
Mathieu Androz

Written by Mathieu Androz

DevOps, Automation & CI/CD addict, Sysadmin, Python fan

No responses yet