zabbix 磁盤自動發現腳本
##需要在zabbix界面配置宏變量===》正則來匹配磁盤
disk_discovery.sh
————————————————————————————————————————————————
#!/bin/bash
# this script is Automatic discovery
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"
————————————————————————————————————————————————
nohup /usr/bin/iostat -dxkt 1 >> /tmp/iostat_output 2>/dev/null & #nohup 讓命令掛在進程裏不中斷 持續執行。也是取數據的文件
disk_status.sh
磁盤發現腳本 ##需要在zabbix 自動發現 來配置 {#DEVICE}
#!/bin/bash
#this scrips is Get disk io info script
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
zabbix 磁盤自動發現腳本