Chinaunix首页 | 论坛 | 博客
  • 博客访问: 672847
  • 博文数量: 121
  • 博客积分: 1425
  • 博客等级: 中尉
  • 技术积分: 2059
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-03 15:34
文章分类

全部博文(121)

文章存档

2018年(1)

2017年(2)

2016年(1)

2015年(11)

2014年(14)

2013年(47)

2012年(45)

分类: IT职场

2013-07-17 09:41:34

#官方默认插件中并无此插件,但官方还是提供了这个插件的下载

#注意:保证所有被监控机上都安装了sysstat包,并可以执行iostat命令
iostat的脚本如下:

点击(此处)折叠或打开

  1. #!/bin/sh
  2. #
  3. # Version 0.0.2 - Jan/2009
  4. # Changes: added device verification
  5. #
  6. # by Thiago Varela - thiago@iplenix.com
  7. iostat=`which iostat 2>/dev/null`
  8. bc=`which bc 2>/dev/null`
  9. function help {
  10. exit -1
  11. }
  12. # Ensuring we have the needed tools:
  13. ( [ ! -f $iostat ] || [ ! -f $bc ] ) && \
  14. ( echo "ERROR: You must have iostat and bc installed in order to run this plugin" && exit -1 )
  15. # Getting parameters:
  16. while getopts "d:w:c:h" OPT; do
  17. case $OPT in
  18. "d") disk=$OPTARG;;
  19. "w") warning=$OPTARG;;
  20. "c") critical=$OPTARG;;
  21. "h") help;;
  22. esac
  23. done
  24. # Adjusting the three warn and crit levels:
  25. crit_tps=`echo $critical | cut -d, -f1`
  26. crit_read=`echo $critical | cut -d, -f2`
  27. crit_written=`echo $critical | cut -d, -f3`
  28. warn_tps=`echo $warning | cut -d, -f1`
  29. warn_read=`echo $warning | cut -d, -f2`
  30. warn_written=`echo $warning | cut -d, -f3`
  31. # Checking parameters:
  32. [ ! -b "/dev/$disk" ] && echo "ERROR: Device incorrectly specified" && help
  33. ( [ "$warn_tps" == "" ] || [ "$warn_read" == "" ] || [ "$warn_written" == "" ] || \
  34. [ "$crit_tps" == "" ] || [ "$crit_read" == "" ] || [ "$crit_written" == "" ] ) &&
  35. echo "ERROR: You must specify all warning and critical levels" && help
  36. ( [[ "$warn_tps" -ge "$crit_tps" ]] || \
  37. [[ "$warn_read" -ge "$crit_read" ]] || \
  38. [[ "$warn_written" -ge "$crit_written" ]] ) && \
  39. echo "ERROR: critical levels must be highter than warning levels" && help
  40. # Doing the actual check:
  41. tps=`$iostat $disk | grep $disk | awk '{print $2}'`
  42. kbread=`$iostat $disk | grep $disk | awk '{print $3}'`
  43. kbwritten=`$iostat $disk | grep $disk | awk '{print $4}'`
  44. # Comparing the result and setting the correct level:
  45. if ( [ "`echo "$tps >= $crit_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $crit_read" | bc`" == "1" ] || \
  46. [ "`echo "$kbwritten >= $crit_written" | bc`" == "1" ] ); then
  47. msg="CRITICAL"
  48. status=2
  49. else if ( [ "`echo "$tps >= $warn_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $warn_read" | bc`" == "1" ] || \
  50. [ "`echo "$kbwritten >= $warn_written" | bc`" == "1" ] ); then
  51. msg="WARNING"
  52. status=1
  53. else
  54. msg="OK"
  55. status=0
  56. fi
  57. fi
  58. # Printing the results:
  59. echo "$msg - I/O stats tps=$tps KB_read/s=$kbread KB_written/s=$kbwritten | 'tps'=$tps; 'KB_read/s'=$kbread; 'KB_written/s'=$kbwritten;"
  60. # Bye!
  61. exit $status


#下载之后,放在每台被监控机的/usr/local/nagios/libexec/目录下
#然后更改属组,赋予可执行权限


在被监控机上/usr/local/nagios/etc/nrpe.cfg配置文件里添加
command[check_sda_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 100 -c 200
在监控机/usr/local/nagios/etc/objects/commands.cfg里面添加
define command{
        command_name    check_iostat
        command_line    $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
        }

在监控机/usr/local/nagios/etc/servers/xxx.cfg里添加
define service{
        use                                 local-service
        host_name                      xxxx
        service_description           iostat
        check_command             check_nrpe!check_iostat
        }
然后检查配置是否有误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
阅读(4075) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~