disk_scan.py
#!/usr/bin/env python
from json import dumps
from commands import getoutput
result = {}
disklist = []
disks = getoutput(''' egrep "\\bsd[a-z]\\b|\\bxvd[a-z]\\b|\\bvd[a-z]\\b" /proc/diskstats | awk '{print $3}' ''')
for disk in disks.split("\n"):
    if len(disk)!=0:
        disklist.append({'{#DISK_NAME}':disk})
result["data"] = disklist
print dumps(result,indent=4,sort_keys=True)


vi /usr/local/zabbix/etc/zabbix_agentd.conf

UserParameter=disk.discovery,/usr/bin/python /etc/zabbix/disk_scan.py
UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁盘读的次数
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}'   //磁盘读的毫秒数
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}'    //磁盘写的次数
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}'   //磁盘写的毫秒数
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'  
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}'   
//花费在IO操作上的毫秒数
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'   
   //读扇区的次数(一个扇区的等于512B)
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'  
   //写扇区的次数(一个扇区的等于512B)
UserParameter=custom.vfs.dev.iowait[*],iostat -x 1 2 | grep $1 | tail -n 1 | awk '{print $$10}'

results matching ""

    No results matching ""