3
0

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 3 years have passed since last update.

datadogのsystem.disk.in_useがうまく動かなくてはまった

Posted at

概要

AWSのEC2で構築したUbuntuのディスク使用率監視をdatadog-agentにて行おうと試みたところ、system.disk.in_useのmax値が1のまま変化せず監視が想定通りできずはまった。

環境

インスタンスタイプ: t2.micro
OSバージョン: Ubuntu, 18.04 LTS
EBS: 8GiB, gp2
datadog-agentバージョン: v7.28.1

実現したかったこと

以下クエリでのディスク使用率監視
avg(last_5m):max:system.disk.in_use{system:xxx} by {host} > 閾値

状態

上記クエリの値が常に1のまま変動せず、監視ができない。

解決策

datadog-agentのdisk.dのconf.yamlに以下を記載し、ループデバイスを除外する。

/etc/datadog-agent/conf.d/disk.d/conf.yaml
init_config:
    file_system_global_blacklist:
      - squashfs

instances:
  - use_mount: false

何が起きてたか

dfコマンドで確認したところ、使用率が100%のファイルシステム/dev/loop0, /dev/loop1, /dev/loop2が存在した。
datadog-agentはこれらの値も取得していたため、max値が常に1になってしまっていました。

$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              486408       0    486408   0% /dev
tmpfs             100208     768     99440   1% /run
/dev/xvda1       8065444 2952280   5096780  37% /
tmpfs             501036       0    501036   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs             501036       0    501036   0% /sys/fs/cgroup
/dev/loop0         33152   33152         0 100% /snap/snapd/11588
/dev/loop1         56832   56832         0 100% /snap/core18/1997
/dev/loop2         34176   34176         0 100% /snap/amazon-ssm-agent/3552
tmpfs             100204       0    100204   0% /run/user/1000

ループデバイスとは

任意のファイルを,ファイルシステム(例:ext2)のようにマウントができる機能だ。

参考: ループバックデバイスってなに? - ITmedia エンタープライズ

これらは読み取り専用の仮想デバイスなので、使用率が100%であっても監視上問題ないようです。

除外したいファイルシステムの特定

ループデバイスを除外するためdisk.d/conf.yamlのfile_system_global_blacklistへ対象のファイルシステムを追記する必要がありました。
datadog-agentではファイルシステムの情報をpythonライブラリであるpsutilのdisk_partitionsにより取得していたため、本項にはこのレスポンスに含まれるfstypeを記載する必要があリました。

$ python
>>> import psutil 
>>> psutil.disk_partitions()
  sdiskpart(device='/dev/xvda1', mountpoint='/', fstype='ext4', opts='rw,relatime,discard', maxfile=255, maxpath=4096),
  sdiskpart(device='/dev/loop0', mountpoint='/snap/snapd/11588', fstype='squashfs', opts='ro,nodev,relatime', maxfile=256, maxpath=4096),
  sdiskpart(device='/dev/loop1', mountpoint='/snap/core18/1997', fstype='squashfs', opts='ro,nodev,relatime', maxfile=256, maxpath=4096), 
  sdiskpart(device='/dev/loop2', mountpoint='/snap/amazon-ssm-agent/3552', fstype='squashfs', opts='ro,nodev,relatime', maxfile=256, maxpath=4096)
]

なお、上述したpsutilのdisk_partitionsは/etc/mtabを読み取っていたため、直接こちらを確認する方法でも良さそうでした。
(以下一部抜粋)

$ cat /etc/mtab
/dev/loop0 /snap/snapd/11588 squashfs ro,nodev,relatime 0 0
/dev/loop1 /snap/core18/1997 squashfs ro,nodev,relatime 0 0
/dev/loop2 /snap/amazon-ssm-agent/3552 squashfs ro,nodev,relatime 0 0

まとめ

ループデバイスが原因であるところまではすぐたどり着いたが、除外方法に方法に悩みました。
困った時はソースコードを確認するのが一番でした。
# FIXME (8.X): Exclude special file systems by default
とあったので8系では良くなってるかもしれないです。

3
0
0

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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?