ZabbixのDisk IO情報取得の仕組み
ZabbixがDisk IO情報の取得時にどのような処理を行っているかを軽く追った。
sourceは調査時にダウンロードページにて最新版の4.2.3。また、4.0.9でも同様の処理を行っていることを確認した。
Linuxでは、当該処理を行っている箇所はsrc/libs/zbxsysinfo/linux/diskio.c
。
#if defined(KERNEL_2_4)
# define INFO_FILE_NAME "/proc/partitions"
# define PARSE(line) if (sscanf(line, ZBX_FS_UI64 ZBX_FS_UI64 " %*d %s " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d %*d %*d %*d", \
&rdev_major, \
&rdev_minor, \
name, \
&ds[ZBX_DSTAT_R_OPER], \
&ds[ZBX_DSTAT_R_SECT], \
&ds[ZBX_DSTAT_W_OPER], \
&ds[ZBX_DSTAT_W_SECT] \
) != 7) continue
#else
# define INFO_FILE_NAME "/proc/diskstats"
# define PARSE(line) if (sscanf(line, ZBX_FS_UI64 ZBX_FS_UI64 " %s " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d %*d %*d %*d", \
&rdev_major, \
&rdev_minor, \
name, \
&ds[ZBX_DSTAT_R_OPER], \
&ds[ZBX_DSTAT_R_SECT], \
&ds[ZBX_DSTAT_W_OPER], \
&ds[ZBX_DSTAT_W_SECT] \
) != 7 \
&& \
/* some disk partitions */ \
sscanf(line, ZBX_FS_UI64 ZBX_FS_UI64 " %s " \
ZBX_FS_UI64 ZBX_FS_UI64 \
ZBX_FS_UI64 ZBX_FS_UI64, \
&rdev_major, \
&rdev_minor, \
name, \
&ds[ZBX_DSTAT_R_OPER], \
&ds[ZBX_DSTAT_R_SECT], \
&ds[ZBX_DSTAT_W_OPER], \
&ds[ZBX_DSTAT_W_SECT] \
) != 7 \
) continue
#endif
Kernel Versionが2.4の場合は/proc/partitions
, それ以外は/proc/diskstats
を見ていることが分かる。
2.4とそれ以外で場合分けをしている理由は、この時にDisk IO情報の出力先が変更されたため。
https://www.kernel.org/doc/Documentation/iostats.txt
In 2.4 now, the information is found as additional fields in
/proc/partitions
. In 2.6 and upper, the same information is found in two
places: one is in the file/proc/diskstats
, and the other is within
the sysfs file system, which must be mounted in order to obtain
the information.On 2.4 you might execute
grep 'hda ' /proc/partitions
. On 2.6+, you have
a choice ofcat /sys/block/hda/stat
orgrep 'hda ' /proc/diskstats
.
diskstatsまたはpartitionsを読んでからの挙動は確認していないが、恐らく前回取得時との差分を取っているのだろう。