nagios监控磁盘I/O小插件,欢迎拍砖
nagios监控磁盘I/O小插件,欢迎拍砖
需要监控磁盘I/O,在网上找了几个nagios相关插件,没有找到太好用的,找了一些监控I/O的脚本,感觉都太复杂,我想实现的目的很简单 就是I/O利用率达到一定范围报警。参考了N多脚本以后,东拼西凑,有了下面的脚本,实现了我自己的需求,分享出来,欢迎大家拍砖。
同时也希望大家经常写nagios的监控脚本多分享。
- #!/bin/sh
- # by siliencen - siliencen@gmail.com
- iostat=`which iostat 2>/dev/null`
- bc=`which bc 2>/dev/null`
- function help {
- echo -e "This plugin shows the I/O usage_rate of the specified disk, using the iostat external program.\n\t example \n\t ./io -d sda2 -w 10 -c 20"
- exit -1
- }
- # Ensuring we have the needed tools:
- ( [ ! -f $iostat ] ) && ( echo "ERROR: iostat command not found .Please install" && exit -1 )
- # Getting parameters:
- while getopts "d:w:c:h" OPT; do
- case $OPT in
- "d") disk=$OPTARG;;
- "w") warning=$OPTARG;;
- "c") critical=$OPTARG;;
- "h") help;;
- esac
- done
- # Adjusting the three warn and crit levels:
- crit_util=`echo $critical`
- warn_util=`echo $warning`
- # Checking parameters:
- [ ! -b "/dev/$disk" ] && echo "ERROR: Device incorrectly specified" && help
- ( [ $warn_util == "" ] || [ $crit_util == "" ] ) && echo "ERROR: You must specify all warning and critical levels" && help
- ( [[ "$warn_util" -ge "$crit_util" ]] ) && echo "ERROR: critical levels must be highter than warning levels" && help
- # Doing the actual check:
- util=`$iostat -dx 1 10 $disk | grep $disk | awk '{print $12}'|sort -nr | head -n 1 `
- # Comparing the result and setting the correct level:
- if ( echo ${util} ${crit_util}|awk '!($1>=$2){exit 1}' );then
- msg="CRITICAL"
- status=2
- else if ( echo ${util} ${warn_util} |awk '!($1>=$2){exit 1}');then
- msg="WARNING"
- status=1
- else
- msg="OK"
- status=0
- fi
- fi
- # Printing the results:
- echo "$msg - I/O stats util_rate=$util "
- # Bye!
- exit $status
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这帖子很不错哦-----顶君一下!!!!!!!!!
深圳进口报关
http://www.chinahq-import.com/
有能监控windows的?
有能监控windows的?