#:编写监控脚本 root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# vim iotop_total.sh #!/bin/bash #Date: 2016/11/11 #Author:zhangjie disk_read(){ NUM=`/usr/bin/sudo iotop -b -n 3 | grep "Total DISK READ" | grep -v grep | awk -F "|" '{print $1}' | awk -F ":" '{print $2}' | tail -n1 | awk -F "/" '{print $1}'` NUM2=`echo $NUM | awk '{print $1}'` UNIT=`echo $NUM | awk '{print $2}'` if [ $UNIT == "B" ];then echo $NUM2 elif [ $UNIT == "K" ];then NUM3=$(echo "$NUM2 * 1024" | bc) echo $NUM3 elif [ $UNIT == "M" ];then NUM3=$(echo "$NUM2 * 1024 * 1024" | bc) echo $NUM3 elif [ $UNIT == "G" ];then NUM3=$(echo "$NUM2 * 1024 * 1024 * 1024" | bc) echo $NUM3 fi } disk_write(){ NUM=`/usr/bin/sudo iotop -b -n 3 | grep "Total DISK WRITE :" | grep -v grep | awk -F "|" '{print $2}' | awk -F ":" '{print $2}' | tail -n1 | awk -F "/" '{print $1}'` NUM2=`echo $NUM | awk '{print $1}'` UNIT=`echo $NUM | awk '{print $2}'` if [ $UNIT == "B" ];then echo $NUM2 elif [ $UNIT == "K" ];then NUM3=$(echo "$NUM2 * 1024" | bc) echo $NUM3 elif [ $UNIT == "M" ];then NUM3=$(echo "$NUM2 * 1024 * 1024" | bc) echo $NUM3 elif [ $UNIT == "G" ];then NUM3=$(echo "$NUM2 * 1024 * 1024 * 1024" | bc) echo $NUM3 fi } main(){ case $1 in disk_read) disk_read; ;; disk_write) disk_write; ;; esac } main $1 #:配置parameter(注意文件存放的位置) root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# vim linux37.conf UserParameter=io_stats[*],/etc/zabbix/zabbix_agentd.conf.d/iotop_total.sh "$1"
#:修改权限
root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# chmod a+x iotop_total.sh
root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# chown zabbix.zabbix linux37.conf
#:重启服务
root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# systemctl restart zabbix-agent
#;在本机测试一下
root@ubuntu:/etc/zabbix/zabbix_agentd.conf.d# bash iotop_total.sh disk_read
#:在server端测试
root@ubuntu:~# /apps/zabbix_server/bin/zabbix_get -s 192.168.7.112 -p 10050 -k "io_stats[disk_read]"
0.00
在web端创建模板----创建监控项(本脚本监控项单位已转换成B)--创建触发器----创建图形----关联模板
例