zabbix监控磁盘IO状态
1.1 导入模板
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比阜平网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式阜平网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖阜平地区。费用合理售后完善,10多年实体公司更值得信赖。
1.2 添加脚本,配置文件
#!/bin/bash sh_file=/data/sh agent_file=/usr/local/zabbix/etc/zabbix_agentd.conf.d/disk_io.conf #zabbix_bin="/usr/local/zabbix" #nohup soft install rpm -qa coreutils >> /dev/null && [ $? = 0 ] || yum -y install coreutils rpm -qa sysstat >> /dev/null && [ $? = 0 ] || yum -y install sysstat zabbix_bin=`echo ${agent_file%/*}` echo $zabbix_bin if [ ! -e "${zabbix_bin}" ];then exit 2 fi #發現腳本 if [ ! -f "${sh_file}/disk_discovery.sh" ];then cat >> ${sh_file}/disk_discovery.sh <<"EOF" #!/bin/bash diskarray=(`cat /proc/diskstats |grep -E "\bsd[a-z]\b|\bxvd[a-z]\b|\bvd[a-z]\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" EOF fi #磁盤狀態監控腳本 if [ ! -f "${sh_file}/disk_status.sh" ];then cat >> ${sh_file}/disk_status.sh <<"EOF" #/bin/sh device=$1 item=$2 case $item in rrqm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $2}' ;; wrqm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $3}';; rps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $4}' ;; wps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $5}';; rKBps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $6}' ;; wKBps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $7}' ;; avgrq-sz) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $8}' ;; avgqu-sz) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $9}' ;; await) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $10}' ;; svctm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $11}' ;; util) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $12}' ;; esac EOF fi #添加配置文件 if [ ! -f " ${agent_file}" ];then cat >> ${agent_file} <<"EOF" UserParameter=disk.discovery,/bin/bash ${sh_file}/discovery.sh UserParameter=disk.status[*],${sh_file}/disk_status.sh $1 $2 EOF #添加清空iostat产生的日志文件 if [ ! -f ${sh_file}/clean_output.sh ];then cat >> ${sh_file}/clean_output.sh <<"EOF" #!/bin/bash #清空/tmp/iostat_output文件,重启进程 Num=`ps aux | grep iostat | grep -v grep |awk '{print $2}' | wc -l` file='/tmp/iostat_output' echo $Num if [ $Num -ne 1 ];then pkill iostat sleep 1 nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi Pid=`ps aux | grep iostat | grep -v grep |awk '{print $2}'` if [ $Pid -gt 1 ];then echo $Pid else nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi count=`cd /tmp/ && ls -lh|grep iostat_output|awk '{print $5}'` if [[ $count > 100K ]];then kill -9 $Pid sleep 1 \mv $file /opt rm -f /opt/iostat_output nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi EOF fi [ -e /etc/init.d/zabbix-agentd ] && /etc/init.d/zabbix-agentd reload
1.3 模板请查看附件
附件:http://down.51cto.com/data/2367517
分享标题:zabbix监控磁盘IO状态
转载来于:http://myzitong.com/article/gsjjio.html