2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

datadogでdocker containerを監視する

Last updated at Posted at 2019-11-14

マニュアルはここ

Dockerのインテグレーションを済ませておく

前提

  • dockerが動いている

監視方法は2通り

  1. hostでdatadog agentを動かす
  2. コンテナとしてdatadog agentを動かす

どちらか一方でよい。これを勘違いしていてhostでもcontainerでも動かしていて
containerのdd-agentがstoppedになってしまっていた。
コンテナはスケールアウトすることを考えるので2でやることが多い。hostにインストールはしない。

hostでdatadog-agentを動かす場合

通常のインストール後に下記を実行

# usermod -a -G docker dd-agent

containerで動かす場合

docker-compose.ymlで起動する場合の例

  • 準備
mkdir -p /usr/local/src/dd-agent
cd /usr/local/src/dd-agent
vi docker-compose.yml
docker-compose.yml
version: "3.4"
services:
  dd-agent:
    image: datadog/agent:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
    environment:
      - DD_API_KEY=xxxxxxxx
      - DD_TAGS="hogeserver role:hoge env:stg"
      - SD_BACKEND=docker

不要な監視の除外設定

/etc/datadog-agent/conf.d/disk.d/conf.yaml
init_config:
instances:
  - use_mount: false
    file_system_blacklist:
      - tmpfs
      - none
      - shm
      - nsfs
      - netns
      - binfmt_misc
      - autofs
    mount_point_blacklist:
      - /var/lib/docker/(containers|overlay2)/
      - /run/docker/
      - /sys/kernel/debug/
      - /run/user/1000/

↑これを書かないと /var/log/datadog/agent.log に [Errno 13] Permission deniedがたくさん出ていた

下記は書かなくても動くらしいけど念の為

/etc/datadog-agent/conf.d/docker.d/conf.yaml
init_config:

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

dd-agentを起動する

docker-compose up -d

確認

# datadog-agent status | grep -A 7 docker
    docker
    ------
      Instance ID: docker [OK]
      Configuration Source: file:/etc/datadog-agent/conf.d/docker.d/conf.yaml
      Total Runs: 202
      Metric Samples: Last Run: 114, Total: 23,028
      Events: Last Run: 0, Total: 0
      Service Checks: Last Run: 1, Total: 202
      Average Execution Time : 11ms

起動後

  • /var/log/datadog/agent.logを確認する
  • メトリクスは docker-xx が取れているか確認する
  • ホストでdocker statsコマンドでdd-agentが動いているか確認する

参考

2
1
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?