天天看点

nagios 监控apache nginx apache

一、nagios监控apache

1、开启apache status

在httpd.conf文件中添加如下内容:

ExtendedStatus On

<Location /server-status>

SetHandler server-status

Order Deny,Allow

Deny from all

Allow from 192.168.10.0/24

</Location>

#重新启动apache,记得先看看apache有status模块./apachectl –l|grep mod_status.c )

2、apache的脚本check_apachestatus.pl来源于http://exchange.nagios.org/directory/Plugins/Web-Servers/Apache/check_apachestatus/details

wget http://www.ealook.com/download/check_apachestatus.pl

chmod 755 check_apachestatus.pl

chown nagios:nagios check_apachestatus.pl

perl -MCPAN -eshell

cpan> install Bundle::LWP

3、测试脚本

./check_apachestatus.pl -H 192.168.10.17

OK 0.113984 seconds response time. Idle 4, busy 1, open slots 251 | 4;0;0;1;0;0   ;0;0;0;0;251

#添加command.cfg

vim /usr/local/nagios/etc/objects/commands.cfg

# 'check_apache' command definition

define command{

command_name check_apache

command_line $USER1$/check_apachestatus.pl -H $HOSTADDRESS$ $ARG1$ $ARG2$

}

/usr/local/nagios/etc/linux/192.168.10.17.cfg

define service {

       use generic-service

       host_name       192.168.10.17

       service_description Apache status

       check_command check_apache

       max_check_attempts 5

       normal_check_interval 1

               }

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

service nagios restart

二、nagios监控mysql

wget http://labs.consol.de/wp-content/uploads/2011/08/check_mysql_health-2.1.7.tar.gz

wget http://www.ealook.com/download/check_mysql_health-2.1.7.tar.gz

tar zxvf check_mysql_health-2.1.7.tar.gz

cd check_mysql_health-2.1.7

./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl

make ;make install

/usr/local/nagios/libexec

./check_mysql_health --hostname 192.168.10.17 --port 3306 --username yan --password yan --mode threads-connected --warning 700 --critical 1000

OK - 2 client connection threads | threads_connected=2;700;1000

define service{

        use                             local-service         ; Name of service template to use

        host_name                       192.168.10.17

        service_description             check_mysql_connections

        check_command                   check_mysql_health!192.168.10.17!3306!yan!yan!threads-connected!1000!1500

        max_check_attempts 5

        normal_check_interval 1

        }

        service_description             check_mysql_table_lock

        check_command                   check_mysql_health!192.168.10.17!3306!yan!yan!table-lock-contention!1!2

       }

三、nagios 监控nginx

#check_nginx.sh 下载

wget http://www.ealook.com/download/check_nginx.sh

#被监控端

vim /usr/local/nginx/conf/nginx/conf

#开启status

location /status {

stub_status on;

access_log   off;

vim /usr/local/nagios/etc/nrpe.conf

command[check_nginx_sh]=/usr/local/nagios/libexec/check_nginx.sh -H 192.168.10.8 -P 80 -p /usr/local/nginx/logs -n nginx.pid -s status  -w 15000 -c 20000

#重启nrpe kill -9 进程号

#启动nrpe

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

#监控端

vim /usr/local/nagios/etc/linux/192.168.10.17.cfg

        use     generic-service

        host_name       192.168.10.8

        service_description     check_nginx

        check_command           check_nrpe!check_nginx_sh

上一篇: Apache
下一篇: HTTP协议简介

继续阅读