前面我们写了nagios的server端和client端的安装过程,这里我们写一下nagios的监控范例
添加监控本地服务器磁盘,监控/dev/sda3,即/分区
[[email protected] ~]# df -h Filesystem 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 #编辑相应配置文件 [[email protected] ~]# 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$ } #修改文件,添加要监控的分区 [[email protected] ~]# 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 } #用命令进行调试 [[email protected] ~]# /usr/local/nagios/libexec/check_disk -w 30% -c 20% /dev/sda3 DISK OK - free space: / 92072 MB (98% inode=99%);| /=1544MB;69038;78900;0;98626 #检查配置文件 [[email protected] ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #重启nagios服务 [[email protected] ~]# service nagios restart Running configuration check...done. Stopping nagios: done. Starting nagios: done.
查看结果
这里我们监控我们前一篇文章中的nagios-client:192.168.3.72的sdb
#编辑文件 [[email protected] ~]# vim /usr/local/nagios/etc/nrpe.cfg command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 #添加sdb这一行 command[check_sdb]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sdb command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 #重启nrped服务 [[email protected] ~]# service nrped restart Stopping NRPE daemon... done. Starting NRPE daemon... done. [[email protected] ~]# netstat -anpt |grep nrpe tcp 0 0 192.168.3.72:5666 0.0.0.0:* LISTEN 1492/nrpe
在nagios-server:192.168.3.71进行配置
[[email protected] objects]# pwd /usr/local/nagios/etc/objects [[email protected] objects]# vim commands.cfg #在末尾添加如下内容 define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } [[email protected] etc]# pwd /usr/local/nagios/etc [[email protected] etc]# vim nagios.cfg #在第36行添加 cfg_file=/usr/local/nagios/etc/objects/192.168.3.72.cfg [[email protected] objects]# pwd /usr/local/nagios/etc/objects [[email protected] 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 local-service host_name 192.168.3.72 service_description check_disk_sdb check_command check_local_disk!30%!20!/dev/sdb notifications_enabled 1 } #检查配置文件 [[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #重启nagios服务 [[email protected] objects]# service nagios restart Running configuration check...done. Stopping nagios: done. Starting nagios: done.
查看结果
1
时间: 2024-10-07 02:18:46