nagios监控实例
前面我们写了nagios的server端和client端的安装过程,这里我们写一下nagios的监控范例
添加监控本地服务器磁盘,监控/dev/sda3,即/分区
[root@nagios-server ~]# 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 #编辑相应配置文件 [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/sda3 DISK 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 restart Running 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.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服务 [root@nagios-client ~]# service nrped restart Stopping NRPE daemon... done. Starting NRPE daemon... done. [root@nagios-client ~]# 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进行配置
[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 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 } #检查配置文件 [root@nagios-server objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #重启nagios服务 [root@nagios-server objects]# service nagios restart Running configuration check...done. Stopping nagios: done. Starting nagios: done.
查看结果
1
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1654981
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。