#######################监控端口是否开启

 监控远程主机端口

】客户端

1、修改nrpe,添加

command[check_5666]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 5666

command[check_3306]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 3306

重启nrpe

--这里的地址是写本地的,并不是写服务器的,是因为通过check_tcp脚本取得某端口状态后再通过nrpe返回给nagios服务端,然后出现在web中

 】】服务端

1、修改services.cfg,添加

define service{

        host_name               xx

        service_description     mysql_3306

#        check_command           check_nrpe!check_tcp!3306

        check_command           check_nrpe!check_3306

--如果注释check_3306那一行的话,可能会出现

NRPE: Command 'check_tcp' not defined

--此处的定义是指并未在客户端那里定义

但是可以仍然可以在服务器端用check_nrpe获取3306的相关信息

root># ./check_nrpe -H xx -c check_3306

TCP OK - 0.000 second response time on port 3306|time=0.000177s;;;0.000000;10.000000

但是使用 check_tcp的话就不行了

因为对象check_3306是通过check_tcp来获取结果的,而check_tcp已经在command.cfg中定义了,所以不需要为check_tcp在进行定义了

###############监控内存

【客户端】

1、添加脚本:cat 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 expression  free * 100 / total

FREETMP=`expr $FREE \* 100`

PERCENT=`expr $FREETMP / $TOTAL`

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

exit 0

并且把该脚本复制到/usr/local/nagios/libexec,赋予执行权限,属主改为nagios
 

 2、修改配置文件,定义

command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 150 -c 100

3、在客户端测试脚本,并重启nrpe

 root># ./check_mem.sh 

200 MB (1%) Free Memory

【服务端】--监控远程主机内存

1、修改services.cfg

 define service{

        host_name               xx

        service_description     Memory

        check_command           check_nrpe!check_mem

        max_check_attempts      5

        normal_check_interval   3

        retry_check_interval    2

        check_period            24x7

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        contact_groups          shyygroup

        }

重启nagios

##如果是要监控本机的内存的话:

1、需要在libexec目录内添加check_mem.sh脚本,并在commands.cfg定义

 define command{

        command_name    check_mem

        command_line    $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$

      }

 然后才是引用,修改services.cfg

 define service{

        host_name               bb

        service_description     Current mem

        check_command           check_mem!180!200

        max_check_attempts      5

        normal_check_interval   3

        retry_check_interval    2

        check_period            24x7

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        contact_groups          shyygroup

        }

 重启nagios即可