前面我们写了nagios的server端和client端的安装过程,这里我们写一下nagios的监控范例
添加监控本地服务器磁盘,监控/dev/sda3,即/分区
[root@nagios-server ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 97G 1.6G 90G 2% /tmpfs 495M 0 495M 0% /dev/shm/dev/sda1 194M 28M 156M 16% /boot#编辑相应配置文件[root@nagios-server ~]# vim /usr/local/nagios/etc/objects/commands.cfg #从这个文件中我们知道该监控脚本需要3个参数define command{ command_name check_local_disk command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ }#修改文件,添加要监控的分区[root@nagios-server ~]# vim /usr/local/nagios/etc/objects/localhost.cfg define service{ use local-service host_name localhost service_description disk_monitor check_command check_local_disk!30%!20!/dev/sda3 notifications_enabled 1 }#用命令进行调试[root@nagios-server ~]# /usr/local/nagios/libexec/check_disk -w 30% -c 20% /dev/sda3DISK OK - free space: / 92072 MB (98% inode=99%);| /=1544MB;69038;78900;0;98626#检查配置文件[root@nagios-server ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #重启nagios服务[root@nagios-server ~]# service nagios restartRunning configuration check...done.Stopping nagios: done.Starting nagios: done.
查看结果
这里我们监控我们前一篇文章中的nagios-client:192.168.3.72的sdb
#编辑文件[root@nagios-client ~]# vim /usr/local/nagios/etc/nrpe.cfgcommand[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3#添加sdb这一行command[check_sdb]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sdbcommand[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 #重启nrped服务[root@nagios-client ~]# service nrped restartStopping NRPE daemon... done.Starting NRPE daemon... done.[root@nagios-client ~]# netstat -anpt |grep nrpetcp 0 0 192.168.3.72:5666 0.0.0.0:* LISTEN 1492/nrpe
在nagios-server:192.168.3.71进行配置
[root@nagios-server objects]# pwd/usr/local/nagios/etc/objects[root@nagios-server objects]# vim commands.cfg#在末尾添加如下内容define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }[root@nagios-server etc]# pwd/usr/local/nagios/etc[root@nagios-server etc]# vim nagios.cfg#在第36行添加cfg_file=/usr/local/nagios/etc/objects/192.168.3.72.cfg[root@nagios-server objects]# pwd/usr/local/nagios/etc/objects[root@nagios-server objects]# cat 192.168.3.72.cfg define host{ use linux-server host_name 192.168.3.72 alias nagios-client address 192.168.3.72 }define hostgroup{ hostgroup_name clients alias linux-servers members 192.168.3.72 }define service{ use generic-service host_name 192.168.3.72 service_description check_disk_sdb check_command check_nrpe!check_sdb notifications_enabled 1 } define service{ use generic-service host_name 192.168.3.72 service_description check_disk_sda3 check_command check_nrpe!check_sda3 notifications_enabled 1 }[root@nagios-server objects]# chown nagios.nagios 192.168.3.72.cfg #检查配置文件[root@nagios-server objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #重启nagios服务[root@nagios-server objects]# service nagios restartRunning configuration check...done.Stopping nagios: done.Starting nagios: done.
查看结果