實現 nagios 監控內存

 1、check_mem腳本

   #!/bin/bash

   # check memory script

   # Total memory 

   TOTAL=`free -m | head -2 |tail -1 |awk '{print $2}'`

   # Free memory 

   FREE=`free -m | head -2 |tail -1 |awk '{print $4}'`

   # Buffers 

    BUFFERS=`free -m | head -2 |tail -1 |awk '{print $6}'`

    # CACHED

   CACHE=`free -m | head -2 |tail -1 |awk '{print $7}'`

   # to calculate free percent

   # use the expression  free * 100 / total

   FREETMP=`expr $FREE \* 100`

   BUFFERSTMP=`expr $BUFFERS \* 100`

   CACHETMP=`expr $CACHE \* 100`

   FREE_PERCENT=`expr $FREETMP / $TOTAL`

   BUFFERS_PERCENT=`expr $BUFFERS / $TOTAL`

   CACHE_PERCENT=`expr $CACHE / $TOTAL`

   echo "$FREE MB ($FREE_PERCENT%) Free Memory"

   echo "$BUFFERS MB ($BUFFERS_PERCENT%) Free Memory"

   echo "$CACHE MB ($CACHE_PERCENT%) Free Memory"

   exit 0

 #將上面的內容複製到/usr/local/nagios/libexec/check_mem

 #並用chmod +x check_mem 爲這個插件添加執行功能

 #在command.cfg中添加一項check_mem的內容如下

 # 'check_mem' command definition

 define command{

         command_name    check_mem

         command_line    $USER1$/check_mem -H $HOSTADDRESS$

         }

 #接下來可以在services.cfg文件中添加了一項內存的監控如下

 define service{

         host_name               nagios-server

         service_description     check_mem

         check_command           check_mem

         max_check_attempts      5

         normal_check_interval   3

         retry_check_interval    2

         check_period            24x7

         notification_period     24x7

         notification_options    w,u,c,r

         }

 記得最後測試一下配置文件

 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章