赞
踩
需要监控每台服务器的磁盘I/O,由于每台服务器的磁盘名称可能不一样,所以需要用到Zabbix的LLD功能来发现磁盘并监控I/O。
一、客户端(被监控端)
1.发现磁盘的脚本(disk_discovery.sh)
#!/bin/bash #written by lenwood #mail: diskarray=(`cat /proc/diskstats |grep -E "\b[sv]d[abcdefg]\b|\bxvd[abcdefg]\b"|grep -i "\b$1\b"|awk '{print $3}'|sort|uniq 2>/dev/null`) length=${#diskarray[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#DISK_NAME}\":\"${diskarray[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n"
我把这个脚本放到zabbix-agent的/etc/zabbix/os目录下
执行结果如下:
root@ubuntu:~# ./disk_discovery.sh
{
"data":[
{"{#DISK_NAME}":"sda"}
]
}
说明:执行结果看到此台测试机上面只有一块磁盘sda
2.获取磁盘I/O信息
a.使用iostat收集磁盘I/O信息(这条指令是每隔一秒将磁盘信息内容写入到/tmp/iostat_output,并且后台运行)
1.apt-get install sysstat(有些机器上面没有安装sysstat,如果有了可以忽略此步骤)
安装完之后可以使用 iostat 展示信息如下:
root@ubuntu:~# iostat
Linux 4.4.0-21-generic (ubuntu) 10/28/2019 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.74 0.00 0.55 0.74 0.00 97.97
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 2.68 8.19 52.80 1383496 8915276
root@ubuntu:~#
安装
在zabbix-agent.conf中增加参数
#### enable Include in config
# /etc/zabbix/zabbix_agentd.conf
echo "Include=/etc/zabbix-agent.d/*.conf" >> /etc/zabbix/zabbix_agentd.conf
#### copy config
mkdir -p /etc/zabbix-agent.d/ && cd /etc/zabbix-agent.d/
curl -O 'https://raw.githubusercontent.com/dusharu/ZBX_Disk_Stat/master/config_zabbix-agent/Disk_Stat.conf'
#### restart zabbix-agent
# RHEL/CentOS
systemctl restart zabbix-agentd
# Debian/Ubuntu
systemctl restart zabbix-agent
# Gentoo
/etc/init.d/zabbix-agentd restart
Zabbix官方模板
wgethttps://github.com/dusharu/ZBX_Disk_Stat/blob/master/Template_ZBX/ZBX_Disk_Stat.xml
测试发现
zabbix_get -s <IP|Server_Name> -k custom.blkdev.discovery |jq .
获得统计量
zabbix_get -s <IP|Server_Name> -k custom.blkdev.all_stat[vg00-lv_root] | jq .
监控磁盘I/O官方脚本
https://github.com/dusharu/ZBX_Disk_Stat/blob/master/Develop/scripts/blkdev_discovery_awk.sh
https://github.com/dusharu/ZBX_Disk_Stat/blob/master/Develop/scripts/blkdev_get_param_awk.sh
https://github.com/dusharu/ZBX_Disk_Stat/blob/master/Develop/scripts/blkdev_show_stat.sh
官方监控模板
https://github.com/dusharu/ZBX_Disk_Stat/blob/master/Template_ZBX/ZBX_Disk_Stat.xml
官方监控配置文件Disk_Stat.conf
##### ZBX_Disk_Stat #####
# Downloaded from:
# https://github.com/dusharu/ZBX_Disk_Stat
#
# Docs:
# https://www.kernel.org/doc/Documentation/admin-guide/iostats.rst
# https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
#### Discovery ####
UserParameter=custom.blkdev.discovery,awk ' BEGIN { printf("{\n\t\"data\":["); } { if (FNR != 1) {printf ("\t},")}; printf("\n\t\t{\t\"{#DEVBLK}\":\""); if (match($3, /^dm-[0-9]*/)) { system("ls -l /dev/mapper/ |grep -e \"../" $3 "$\" | awk \"{print \\$9}\"|tr -d \"\\n\""); } else { printf($3); }; printf("\""); } END { {printf ("\t}\n")} printf("\t]\n}\n"); }' /proc/diskstats
#### Get Stat ####
UserParameter=custom.blkdev.all_stat[*],DISK="$1"; if [[ ! -b "/dev/$DISK" ]]; then DISK="$( ls -l /dev/mapper/ |awk "/ $DISK / {gsub(\"../\",\"\",\$$11);print \$$11}" )"; fi; if [[ "$DISK" != "" ]]; then grep -m1 " $DISK " /proc/diskstats | column --json --table-name ZBX_Disk_Stat --table-columns major,minor,name,read_complete,read_merge,read_sector,read_time,write_complete,write_merge,write_sector,write_time,io_queue,io_time,io_time_weight,discard_complete,discard_merge,discard_sector,discard_time --table-hide major,minor,read_merge,write_merge,io_time,io_time_weight,discard_complete,discard_merge,discard_sector,discard_time; else exit 100; fi
地址:https://github.com/dusharu/ZBX_Disk_Stat/blob/master/config_zabbix-agent/Disk_Stat.conf
参考链接
https://www.iteye.com/blog/20120923lina-2258119
https://github.com/dusharu/ZBX_Disk_Stat
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。