Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670223
  • 博文数量: 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-16 11:14:27

首先一点  我们安装的nagios是没有自带内存监控插件  需要自己定义脚本来写

内存的监控脚本如下:
在此目录下/usr/local/nagios/libexec
chechk_mem.sh

点击(此处)折叠或打开

  1. #script to check real memory usage
  2. # ------------------------------------------
  3. # ######## Script Modifications ##########
  4. # ------------------------------------------
  5. # zhangzhengxing
  6. # --- ---- ----
  7. #
  8. #!/bin/bash
  9. USAGE="`basename $0` [-w|--warning] [-c|--critical]"
  10. THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"
  11. calc=/tmp/memcalc
  12. percent_free=/tmp/mempercent
  13. critical=""
  14. warning=""
  15. STATE_OK=0
  16. STATE_WARNING=1
  17. STATE_CRITICAL=2
  18. STATE_UNKNOWN=3
  19. # print usage
  20. if [[ $# -lt 4 ]]
  21. then
  22.         echo ""
  23.         echo "Wrong Syntax: `basename $0` $*"
  24.         echo ""
  25.         echo "Usage: $USAGE"
  26.         echo ""
  27.         exit 0
  28. fi
  29. # read input
  30. while [[ $# -gt 0 ]]
  31.   do
  32.         case "$1" in
  33.                -w|--warning)
  34.                shift
  35.                warning=$1
  36.         ;;
  37.                -c|--critical)
  38.                shift
  39.                critical=$1
  40.         ;;
  41.         esac
  42.         shift
  43.   done

  44. # verify input
  45. if [[ $warning -eq $critical || $warning -lt $critical ]]
  46. then
  47.         echo ""
  48.         echo "$THRESHOLD_USAGE"
  49.         echo ""
  50.         echo "Usage: $USAGE"
  51.         echo ""
  52.         exit 0
  53. fi
  54. # Total memory available
  55. total=`free -m | head -2 |tail -1 |gawk '{print $2}'`
  56. # Total memory used
  57. used=`free -m | head -2 |tail -1 |gawk '{print $3}'`
  58. # Calc total minus used
  59. free=`free -m | head -2 |tail -1 |gawk '{print $2-$3}'`
  60. # normal values
  61. #echo "$total"MB total
  62. #echo "$used"MB used
  63. #echo "$free"MB free
  64. # make it into % percent free = ((free mem / total mem) * 100)
  65. echo "5" > $calc # decimal accuracy
  66. echo "k" >> $calc # commit
  67. echo "100" >> $calc # multiply
  68. echo "$free" >> $calc # division integer
  69. echo "$total" >> $calc # division integer
  70. echo "/" >> $calc # division sign
  71. echo "*" >> $calc # multiplication sign
  72. echo "p" >> $calc # print
  73. percent=`/usr/bin/dc $calc|/bin/sed 's/^\./0./'|/usr/bin/tr "." " "|/usr/bin/gawk {'print $1'}`
  74. #percent1=`/usr/bin/dc $calc`
  75. #echo "$percent1"
  76. if [[ "$percent" -le $critical ]]
  77.         then
  78.                 echo "CRITICAL - $free MB ($percent%) Free Memory"
  79.                 exit 2
  80. fi
  81. if [[ "$percent" -le $warning ]]
  82.         then
  83.                 echo "WARNING - $free MB ($percent%) Free Memory"
  84.                 exit 1
  85. fi
  86. if [[ "$percent" -gt $warning ]]
  87.         then
  88.                 echo "OK - $free MB ($percent%) Free Memory"
  89.                 exit 0
  90. fi

 

 

vim /usr/local/nagios/etc/objects/commands.cfg
#增加以下内容
define command{
                command_name        check_mem
                command_line        $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$
                }


 #修改客户端配置文件 
 vim /usr/local/nagios/etc/nrpe.cfg 
#找到相同的地方增加以下内容    
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 10 -c 5


/usr/local/nagios/etc/servers/xxxx.cfg添加
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       192.168.1.x
        service_description             memory
        check_command                check_nrpe!check_mem!110,80!150,100
       }




阅读(2081) | 评论(0) | 转发(0) |
0

上一篇:dell 服务热线

下一篇:nagios 监控mysql

给主人留下些什么吧!~~