Zabbix2.2でローレベルディスカバリ(LLD)用の自作スクリプトを使ってdiskstatsを自動登録する設定。inspired by ZabbixでLinuxのHard Disk I/O監視
管理してるサーバーたちのマウントしているファイルシステムがそれぞれバラバラだったので、LLDで検知させる設定を入れてみました。
環境は aws ec2 amazon linux / centos 6.5 あたり
zabbix-agent設定
- /etc/zabbix/zabbix_agentd.d/userparameter_diskstats.conf 設置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserParameter=custom.vfs.dev.read.ops[*],grep -w $1 /proc/diskstats | awk '{print $$4}' | |
UserParameter=custom.vfs.dev.read.ms[*],grep -w $1 /proc/diskstats | awk '{print $$7}' | |
UserParameter=custom.vfs.dev.write.ops[*],grep -w $1 /proc/diskstats | awk '{print $$8}' | |
UserParameter=custom.vfs.dev.write.ms[*],grep -w $1 /proc/diskstats | awk '{print $$11}' | |
UserParameter=custom.vfs.dev.io.active[*],grep -w $1 /proc/diskstats | awk '{print $$12}' | |
UserParameter=custom.vfs.dev.io.ms[*],grep -w $1 /proc/diskstats | awk '{print $$13}' | |
UserParameter=custom.vfs.dev.read.sectors[*],grep -w $1 /proc/diskstats | awk '{print $$6}' | |
UserParameter=custom.vfs.dev.write.sectors[*],grep -w $1 /proc/diskstats | awk '{print $$10}' |
- /etc/zabbix/bin/diskstats_fs_discovery.pl 設置
auto discoery用スクリプト設置。binディレクトリはどこでもいいけど、とりあえず/etc/zabbix 以下に
mkdir bin
して下記ファイルを置く。置いたら
chown -R zabbix. /etc/zabbix/bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# | |
use File::Basename qw/basename/; | |
$first = 1; | |
print "{\n"; | |
print "\t\"data\":[\n\n"; | |
for (`cat /proc/mounts`) | |
{ | |
($fsdevice, $fstype) = m/(\S+) \S+ (\S+)/; | |
$fsdevice = basename $fsdevice; | |
print "\t,\n" if not $first; | |
$first = 0; | |
print "\t{\n"; | |
print "\t\t\"{#FSDEVICE}\":\"$fsdevice\",\n"; | |
print "\t\t\"{#FSTYPE}\":\"$fstype\"\n"; | |
print "\t}\n"; | |
} | |
print "\n\t]\n"; | |
print "}\n"; |
- /etc/zabbix/zabbix_agentd.d/userparameter_discovery.conf
bin/diskstats_fs_discovery.pl をzabbix-serverから読み込めるようにする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserParameter=diskstats.fs.discovery,/etc/zabbix/bin/diskstats_fs_discovery.pl |
zabbix-get で確認
zabbix_get -s <対象> -k diskstats.fs.discovery
でこんな風↓に返ってくればok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data":[ | |
{ | |
"{#FSDEVICE}":"rootfs", | |
"{#FSTYPE}":"rootfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"proc", | |
"{#FSTYPE}":"proc" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"sysfs", | |
"{#FSTYPE}":"sysfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"devtmpfs", | |
"{#FSTYPE}":"devtmpfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"devpts", | |
"{#FSTYPE}":"devpts" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"tmpfs", | |
"{#FSTYPE}":"tmpfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"xvda1", | |
"{#FSTYPE}":"ext4" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"usb", | |
"{#FSTYPE}":"usbfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"none", | |
"{#FSTYPE}":"tmpfs" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"xvdb1", | |
"{#FSTYPE}":"ext4" | |
} | |
, | |
{ | |
"{#FSDEVICE}":"none", | |
"{#FSTYPE}":"binfmt_misc" | |
} | |
] | |
} |
zabbix-server設定
GUIで。Template OS Linux あたりのテンプレートにDiscoveryプロトタイプの設定を追加。
- Create Discovery rule
- Item を追加
各Itemは下記のような感じ。
こんな感じに追加される。
ディスカバリのインターバルを3600秒にしてるので、あとは1時間くらい待てば追加されるはず。