linux 磁盘io监控脚本,zabbix监控linux磁盘io的模板

最近,我发现zabbix没有监控linux的磁盘io,于是借助百度,我做了一个zabbix模板,用来监控磁盘io。

1、添加自动寻找磁盘脚本:

cat /home/monitor/disk_scan.sh

######################################

#!/bin/bash

#written by lenwood

#mail:ccyhaoran@live.cn

diskarray=(`cat /proc/diskstats |grep -E "\bsd[abcdefg]\b|\bxvd[abcdefg]\b"|grep -i "\b$1\b"|awk '{print $3}'|sort|uniq   2>/dev/null`)

length=${#diskarray[@]}

printf "{\n"

printf  '\t'"\"data\":["

for ((i=0;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"

###########################

注释:grep -E 里面的\b表示匹配空字符串的意思。

The Backslash Character and Special Expressions

The symbols \< and \>  respectively  match  the  empty  string  at  the

beginning and end of a word.  The symbol \b matches the empty string at

the edge of a word, and \B matches the empty string provided  it’s  not

at  the edge of a word.  The symbol \w is a synonym for [[:alnum:]] and

\W is a synonym for [^[:alnum:]].

2、后台执行iostat命令

nohup iostat -m -x -d 30 > /home/script/log/iostat_output  &

-c 仅显示CPU统计信息.与-d选项互斥.

-d 仅显示磁盘统计信息.与-c选项互斥.

-k 以K为单位显示每秒的磁盘请求数,默认单位块.

-p device | ALL

与-x选项互斥,用于显示块设备及系统分区的统计信息.也可以在-p后指定一个设备名,如:

# iostat -p hda

或显示所有设备

# iostat -p ALL

-t    在输出数据时,打印搜集数据的时间.

-V    打印版本号和帮助信息.

-x    输出扩展信息.

-m 以兆为单位

3、为了下次开启也生效,把上述的nohup iostat命令加入/etc/rc.local里面

4、在zabbix_agentd.conf中加入如下UserParameters:

############################

#通过iostat  -m -x -d 30 获得的磁盘io信息

UserParameter=io.scandisk[*],/home/script/disk_scan.sh $1

UserParameter=io.rps[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b"|tail -1|awk '{print $$4}'

UserParameter=io.wps[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$5}'

UserParameter=io.rMBps[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$6}'

UserParameter=io.wMBps[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$7}'

UserParameter=io.avgrq-sz[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$8}'

UserParameter=io.avgqu-sz[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$9}'

UserParameter=io.await[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$10}'

UserParameter=io.svctm[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$11}'

UserParameter=io.util[*],/usr/bin/tail /home/script/log/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$12}'

#通过cat /proc/diskstats获得的磁盘io信息

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}'

UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'

UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'

##################

5、重启zabbix agent

/etc/init.d/zabbix_agentd restart

6、确认zabbix agent是否启动

[ ps -elf |grep zabbix

7、导入我弄的模板:linux磁盘io模板-czxin

8、关联你要监控的主机

####################

参考资料:

http://blog.chinaunix.net/uid-26446098-id-4964263.html

附件列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值