zrong 发表于 2019-1-15 08:05:00

nagios用nrpe监控mem

  在监控端及nagios服务器上添加如下脚本
  # cat /usr/local/nagios/libexec/check_mem.sh
  TOTAL=`free -m | head -2 |tail -1 |gawk '{print $2}'`
  # Free memory
  FREE=`free -m | head -2 |tail -1 |gawk '{print $4}'`
  # to calculate free percent
  # use the expressionfree * 100 / total
  FREETMP=`expr $FREE \* 100`
  PERCENT=`expr $FREETMP / $TOTAL`
  echo "$FREE MB ($PERCENT%) Free Memory"
  exit 0
  vim /usr/local/nagios/etc/objects/commands.cfg (添加)
  definecommand{
  command_namecheck_mem
  command_line$USER1/check_mem.sh   -H $HOSTADDRESS$
  }
  vim /usr/local/nagios/etc/objects/services.cfg (添加)
  define service{
  use                     local-service
  host_name               mysqlhost
  service_groupsmysqlgroup
  service_description   check_mem
  check_command         check_nrpe!check_mem.sh
  max_check_attempts      2
  normal_check_interval   3
  retry_check_interval    2
  check_period            24x7
  notification_interval   5
  notification_period   24x7
  notification_options    w,u,c,r
  contact_groups          admins
  }
  在被监控端
  # cat /usr/local/nagios/libexec/check_mem.sh
  TOTAL=`free -m | head -2 |tail -1 |gawk '{print $2}'`
  # Free memory
  FREE=`free -m | head -2 |tail -1 |gawk '{print $4}'`
  # to calculate free percent
  # use the expressionfree * 100 / total
  FREETMP=`expr $FREE \* 100`
  PERCENT=`expr $FREETMP / $TOTAL`
  echo "$FREE MB ($PERCENT%) Free Memory"
  exit 0
  vim /usr/local/nagios/etc/nrpe.cfg (添加)
  command=/usr/local/nagios/libexec/check_mem.sh
  重启xientd服务
  /etc/init.d/xinted restart
  监控端
  重启nagios服务
  /etc/init.d/nagios restart



页: [1]
查看完整版本: nagios用nrpe监控mem