码迷,mamicode.com
首页 > 移动开发 > 详细

zabbix之磁盘IO之IOSTAT

时间:2016-06-02 00:52:37      阅读:486      评论:0      收藏:0      [点我收藏+]

标签:

1. 发现硬盘 disk_discovery.sh
#!/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"
 
Python版本disk_discovery.py
#/usr/bin/python
#This script is used to discovery disk on the server
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=(‘,‘,‘:‘))
 
2. 使用iostat收集磁盘I/O信息
#!/bin/sh
device=$1
item=$2
/usr/bin/iostat -dxkt 1 5 > /tmp/iostat_output 2>/dev/null
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
 
3. 修改Zabbix agent配置文件,添加disk_status.conf
Timeout=10
### Option: UserParameter
#      User-defined parameter to monitor. There can be several user-defined parameters.
#      Format: UserParameter=<key>,<shell command>
#      See ‘zabbix_agentd‘ directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=disk.discovery,/usr/bin/python /usr/local/zabbix/bin/disk_discovery.py
UserParameter=disk.status[*],/usr/local/zabbix/bin/disk_status.sh $1 $2
 
这里需要注意,Zabbix agent默认的Timeout值为3秒,由于这里使用iostat -ydxkt 1 3,每隔1秒刷新一次,刷新3次,所以如果获取磁盘信息Timeout设置时间短了的话会出现ZBX_NOTSUPPORTED这样的错误
然后重新加载zabbix agent
 
4. 通过在zabbix server或zabbix proxy端使用zabbix_get获取磁盘信息
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.190 -p 10055 -k "disk.discovery"
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.190 -p 10055 -k "disk.status[xvda,wps]"10.00

zabbix之磁盘IO之IOSTAT

标签:

原文地址:http://www.cnblogs.com/tankt101/p/5551595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!