entbit. Menu

Cologne, DE

Published
Length
1 min ยท 209 w
Filed under
AWSDatadog

Using Environment Variables in Datadog Agent Configuration.

Have you ever tried to use environment variables in the Datadog agent configuration? Here is how you can do it!

Hey there, ๐Ÿ‘‹

I needed to set up a Datadog agent to check remote Postgres instances as a regular container. All the documentation I found was about injecting secrets like passwords or hostnames via Kubernetes secrets. This seemed to be the only way to do it besides using Docker Swarm secrets. Since I had to set up a container definition for AWS ECS Fargate, neither of these options were available. So I wanted to see if I could use "regular" environment variables from which the agent could pull the secrets on startup.

In the depths of the datadog-agent GitHub repository I found the possibility to use ENVs on startup to configure the agent to start e.g. the postgres database checks. This should not only work in the shown postgres configuration, but be a feature available for the whole datadog-agent.

The syntax is simple. Use %%env_<VARIABLE_NAME>%% - this way the datadog-agent knows where to get the environment variables from.

The following is the Docker label to use to set up additional remote checks in the datadog agent.

com.datadoghq.ad.checks='{"postgres": {
    "init_config": {},
    "instances": [{
      "dbm": true,
      "host": "%%env_POSTGRES_HOST%%",
      "port": 5432,
      "username": "datadog",
      "password": "%%env_POSTGRES_PASSWORD%%",
      "tags": ["dbinstanceidentifier:<DB_INSTANCE_NAME>"]
    }]
  }}'

Thanks for reading & have a nice day! ๐Ÿ‘‹

Niklas

Newsletter ยท entbit.

One email per post.

Deno, AWS, GitHub Actions and whatever I'm debugging. No spam.

Prefer not to hand over your real address? Use an alias from DuckDuckGo, Firefox Relay or Hide My Email.