|
zabbix自动发现硬盘脚本disk_discovery.py
[app@data1 etc]$ cat disk_discovery.py
#/usr/bin/python
import subprocess
import json
args="cat /proc/diskstats |grep -E '\ssd[a-z]\s|\sxvd[a-z]\s|\svd[a-z]\s'|awk '{print $3}'|sort|uniq 2>/dev/null"
t=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0]
disks=[]
for disk in t.split('\n'):
if len(disk) != 0:
disks.append({'{#DISK_NAME}':disk})
print json.dumps({'data':disks},indent=4,separators=(',',':')) zabbix监控硬盘状态脚本
[app@data1 etc]$ cat disk_status.sh
#/bin/sh
device=$1
item=$2
case $item in
rrqm)
/usr/bin/iostat -dx |grep $device |awk '{print $2}';;
wrqm)
/usr/bin/iostat -dx |grep $device |awk '{print $3}';;
rps)
/usr/bin/iostat -dx |grep $device |awk '{print $4}';;
wps)
/usr/bin/iostat -dx |grep $device |awk '{print $5}';;
rKBps)
/usr/bin/iostat -dx |grep $device |awk '{print $6}';;
wKBps)
/usr/bin/iostat -dx |grep $device |awk '{print $7}';;
avgrq-sz)
/usr/bin/iostat -dx |grep $device |awk '{print $8}';;
avgqu-sz)
/usr/bin/iostat -dx |grep $device |awk '{print $9}';;
await)
/usr/bin/iostat -dx |grep $device |awk '{print $10}';;
svctm)
/usr/bin/iostat -dx |grep $device |awk '{print $11}';;
util)
/usr/bin/iostat -dx |grep $device |awk '{print $12}';;
esac 修改zabbix_agentd.conf文件
[app@data1 etc]$ tail -2 zabbix_agentd.conf
UserParameter=disk.discovery,/usr/bin/python /usr/local/zabbix/etc/disk_discovery.py
UserParameter=disk.status
,/usr/local/zabbix/etc/disk_status.sh $1 $2
#说明
$1为自动发现脚本disk_discovery.py返回给zabbix server的{#DISK_NAME}
$2位要监控的选项 监控tcp连接状态
[app@data1 etc]$ tail -1 zabbix_agentd.conf
UserParameter=tcp
,netstat -an |grep -c $1
|
|
|