nagios监控mysql主机,nginx,磁盘IO,网卡流量

http://blog.chinaunix.net/uid-28685162-id-3506260.html


nagios安装完成,打开/usr/local/nagios/etc/nagios.cfg去掉cfg_dir=/usr/local/nagios/etc/servers前面的#号,并创建/usr/local/nagios/etc/servers目录(此目录下放被监控机的配置文件),重启nagios服务service nagios restart
/usr/local/nagios/etc/objects/commands.cfg  定义监控的命令,监控每一项都必须先在此配置文件定义监控命令
/usr/local/nagios/etc/objects/contacts.cfg 定义联系人和联系人组,比如联系人naigosadmin,联系人组admins,报警信息也在这里配置
/usr/local/nagios/etc/objects/timeperiods.cfg 定义时间
/usr/local/nagios/etc/objects/templates.cfg 放置监控模板,可在监控服务的时候引用这里面的模板,一般不用改动
/usr/local/nagios/etc/objects/localhost.cfg 如果你要监控本机,那就在这里配置
/usr/local/nagios/etc/servers 放置被监控机的配置文件,比如我监控192.168.1.252的配置文件252.cfg就放这下面
 
监控机:192.168.1.246
被监控机:192.168.1.252,192.168.1.249
操作系统:RHEL5.4
 
一、监控磁盘IO
先下载脚本所需模块
perl Makefile.PL
make
make install
在被监控机上/usr/local/nagios/etc/nrpe.cfg配置文件里添加
command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 5 -c 10
把脚本check_iostat(见附件)放到被监控机的/usr/local/nagios/libexec/目录下,并赋权限
chmod +x /usr/local/nagios/libexec/check_iostat
Chown nagios:nagios /usr/local/nagios/libexec/check_iostat
测试:[root@Rs-02 libexec]# ./check_iostat -w 5 -c 10
IOSTAT OK - user 0.54 nice 0.01 sys 1.41 iowait 1.37 idle 0.00  | iowait=1.37%;; idle=0.00%;; user=0.54%;; nice=0.01%;; sys=1.41%;;
在监控机/usr/local/nagios/etc/objects/commands.cfg里面添加
define command{
        command_name    check_iostat
        command_line    $USER1$/check_iostat -w $ARG1$ -c $ARG2$
        }
在监控机/usr/local/nagios/etc/servers/252.cfg(被监控机192.168.1.252的配置文件)里添加
define service{
        use                             generic-service
        host_name                       252
        service_description             iostat
        check_command                   check_iostat!5!10
        }
然后检查配置是否有误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
提示无误后重启服务service nagios restart
 
二、监控nginx状态
被监控端nginx配置文件nginx.conf的虚拟主机添加
                location /nginx_status {
                        stub_status on;
                        access_log   off;
                }
把check_nginx(见附件)放到监控端/usr/local/nagios/libexec/目录下,并赋权限
chmod +x /usr/local/nagios/libexec/check_nginx
Chown nagios:nagios /usr/local/nagios/libexec/check_nginx
测试:./check_nginx -H 192.168.1.252 -P 80 -p /usr/local/nginx/ -n nginx.pid -s nginx_status -o /tmp/ -w 15000 -c 20000
OK - nginx is running. 1 requests per second, 1 connections per second (1.00 requests per connection) | 'reqpsec'=1 'conpsec'=1 'conpreq'=1.00 ]
/usr/local/nagios/etc/objects/commands.cfg添加
define command{
        command_name    check_nginxstatus
        command_line    $USER1$/check_nginx -H $ARG1$ -P $ARG2$ -p $ARG3$ -n $ARG4$ -o $ARG5$ -w $ARG6$ -c $ARG7$
        }
/usr/local/nagios/etc/servers/252.cfg添加
define service{
        use                             generic-service
        host_name                       252
        service_description             nginx_status
        check_command                   check_nginxstatus!192.168.1.252!80!/usr/local/nginx!nginx.pid!nginx_status!/tmp!15000!20000
        }
重启nagios服务
 
三、监控网卡流量
被监控机/usr/local/nagios/etc/nrpe.cfg里添加
command[check_iftraffic]=/usr/local/nagios/libexec/check_iftraffic -i eth0 -w 50 -c 100 -b 100 -u m
把check_iftraffic(见附件)放到被监控机/usr/local/nagios/libexec/目录下,并赋权限
chmod +x /usr/local/nagios/libexec/check_iftraffic
Chown nagios:nagios /usr/local/nagios/libexec/check_iftraffic
监控端/usr/local/nagios/etc/objects/commands.cfg添加
define command{
         command_name    check_iftraffic
         command_line    $USER1$/check_iftraffic -H $HOSTADDRESS$ -i $ARG1$ -w $ARG2$ -c $ARG3$ -b $ARG4$ -u $ARG5$
}
/usr/local/nagios/etc/servers/252.cfg添加
define service{
        use                             generic-service
        host_name                       252
        service_description             iftraffic
        check_command                   check_nrpe!check_iftraffic!"eth0"!50!100!100!m
        }
重启nagios服务
 
四、监控Mysql主机
用plugin 产生的脚本 check_mysql监控
需要被监控机添加访问
• 据库授权:(登陆DB服务器,进行授权用户名 liuyu,密码linu
• mysql> grant all privileges on *.* to chenwei@192.168.1.246 identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
监控端/usr/local/nagios/etc/objects/commands.cfg添加
define command{
        command_name    check_mysql
        command_line    $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$
        }
/usr/local/nagios/etc/servers/252.cfg添加
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       252
        service_description             mysql
        check_command                   check_mysql!192.168.1.252!3306!chenwei!123456
#       notifications_enabled           0    此项定义是否发送报警信息,0为关闭,1为开启
        }
重启nagios服务
 
监控脚本在附件里

posted @ 2014-04-02 15:00  dingxiaoyue  阅读(222)  评论(0编辑  收藏  举报