Join us at the Dash conference! July 16-17, NYC

DogStatsD and Docker

Datadog has a large number of integrations with common applications, but it can also be used to instrument your custom applications. This is typically using one of the many Datadog libraries.

Libraries that communicate over HTTP using the Datadog API don’t require any special configuration with regard to Docker. However, applications using libraries that integrate with DogStatsD or StatsD need the library configured to connect with the Agent. Each library handles this configuration differently, so refer to the individual library’s documentation for more details.

After your code is configured, run your custom application container using the --link option to create a network connection between your application container and the Datadog Agent container.

Example: Monitoring a basic Python application

To monitor your application, run the Datadog container using the Basic Docker Agent usage instructions. The docker run command sets the name of the container to dd-agent.

Next, instrument your code. Here’s a basic Flask-based web application:

from flask import Flask
from datadog import initialize, statsd

# Initialize DogStatsD and set the host.
initialize(statsd_host = 'dd-agent')

app = Flask(__name__)

def hello():
    # Increment a Datadog counter.

    return "Hello World!"

if __name__ == "__main__"

In our example code above, the DogStatsD host must match the Datadog Agent container name, dd-agent.

After building the web application container, run it and use the --link argument to setup a network connection to the Datadog Agent container:

docker run -d --name my-web-app \
    --link dd-agent:dd-agent

For another example using DogStatsD, see our Docker Compose example project on GitHub.