Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29954395
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: 系统运维

2010-09-07 13:18:08

nagios来监控WEB应用状态

时间:2010-9-7

第一部分 nagios来监控网页

想使用Nagios监控网页状况,Nagios插件中的一个命令不得不被提及,那就是check_http,我没可以使用它来检查网页是否正常、可用。该命令的具体说明和用法如下。

 


-H, --hostname=ADDRESS
主机名或域名
-I, --IP-address=ADDRESS server
IP地址,用于在不能DNS的情况下
-p, --port=INTEGER
端口号,默认80
-u, --url=PATH url
,默认是/
-w, --warning=DOUBLE warning
状态的响应时间,单位是秒
-c, --critical=DOUBLE critical
状态的响应时间,单位是秒
-t, --timeout=INTEGER
连接超时时间,默认10

 

举一个简单的实例,一个网站的域名是,端口是默认80,需要监测它的主页/index.htmlwarning时间和critical时间、 timeout时间使用默认值,不设置。具体命令书写如下。

$ ./check_http -H -u /index.html
HTTP OK HTTP/1.1 200 OK - 115357 bytes in 1.717 seconds |time=1.716934s;;;0.000000 size=115357B;;;0


可以看出该网页是正常的,如果网页地址不对或显示有错误也会有相应的反馈信息。

 

3. 具体配置Nagios来监控网页

通过Nagios监控网页一般有两种方式,一种是直接通过Nagios监控主机配置监控服务监视网页;另一种是在某一安装了NRPE的客户端主机上配置监 控命令,通过NRPE监控网页情况,再将结果传回给Nagios监控主机。通过一个装有NRPE的客户端作为桥梁的方式可以使主机更加安全,减轻 Nagios主机的负担,同时可以避免在Nagios主机上配置DNS等不必要的麻烦。

(这种可配置的方式其实跟现在的运维平台可以结合起来。就是把这种灵活的可配置的方式将其纳入到运维平台里面去)

 

 

方式一、直接通过Nagios主机监控网页。

相当于是设置一个监控点然后从各台取回来数据的。

说明:这个架构存在的一个问题可能就是还存在一种单点故障的情况。

方式一的配置十分简单,只需要在Nagios的配置文件里添加一个服务即可。
配置内容如下
修改./etc/objects/commands.cfg,增加如下内容。

#''check_http'' check web pagedefine command{ command_name check_webpage command_line $USER1$/check_http $ARG1$ }


修改./etc/objects/localhost.cfg,增加如下内容。

define host{ use linux-server host_name web_pages alias web_pages address 127.0.0.1 } #the check web pages on the remote host.define service{ use generic-service host_name web_pages ;
主机名,为了便于显示可以定义一个虚拟的host service_description web page1 check_command check_webpage!-H -u /index.html }

 

结论:nagios不光只是说能够监控一台主机的存活情况还可以监控这台主机上面的应用是否存活的情况的。

 

 

 

第二部分 用它来监控MYSQL的状态

公司MySQL从服务器经常中断服务,网上找到一个nagios插件,专门用于监控服务复制状态。

 

文档资料

安装插件
# wget /svn/trunk/nagios/check_mysql_replication/check_mysql_replication.pl
# mv check_mysql_replication.pl /usr/local/nagios/libexec/check_mysql_replication
# chmod 755 /usr/local/nagios/libexec/check_mysql_replication
# yum -y install perl-DBD*

check_mysql_replication命令资料
Usage: check_mysql [-d database] [-H host] [-P port] [-s socket] [-u user] [-p password] [-S]
Options:
-h, –help Print detailed help screen
-V, –version Print version information
-H, –hostname=ADDRESS Host name, IP Address, or unix socket (must be an absolute path)
-P, –port=INTEGER Port number (default: 3306)
-s, –socket=STRING Use the specified socket (has no effect if -H is used)
-d, –database=STRING Check database with indicated name
-u, –username=STRING Connect using the indicated username
-p, –password=STRING Use the indicated password to authenticate the connection
==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==
Your clear-text password could be visible as a process table entry
-S, –check-slave Check if the slave thread is running properly.
-w, –warning Exit with WARNING status if slave server is more than INTEGER seconds behind master
-c, –critical Exit with CRITICAL status if slave server is more then INTEGER seconds behind master

There are no required arguments. By default, the local database is checked using the default unix socket. You can force TCP on localhost by using an IP address or FQDN (’localhost’ will use the socket as well).

Send email to nagios-users@lists.sourceforge.net if you have questions regarding use of this software. To submit patches or suggest improvements,send email to nagiosplug-devel@lists.sourceforge.net

check_mysql_replication命令资料
check_replication.pl [ --slave ] [ --slave-pass][ --slave-port ] [ --slave-user ] [ --master ]
[ --master-pass] [ --master-port] [ --master-user ][ --crit] [ --warn] [ --check-random-database ]
[ --table-rows-diff-absolute-crit ][ --table-rows-diff-absolute-warn ]

–slave - MySQL instance running as a slave server
–slave-port - port for the slave
–slave-user - Username with File/Process/Super privs
–slave-pass
- Password for above user
–master - MySQL instance running as server (override)
–master-port - port for the master (override)
–master-user - Username for master (override)
–master-pass
- Password for master

–crit
- Number of complete master binlogs for critical state
–warn
- Number of complete master binlog for warning state

–check-random-database - Select a random DB from the slave’s list of databases and compare to the master’s information for these (need SELECT priv)

–table-rows-diff-absolute-crit - If we do the check-random-database,then ensure that the change in row count between master and slave is below this threshold, and go critical if not

–table-rows-diff-absolute-warn - If we do the check-random-database,then ensure that the change in row count between master and slave is below this threshold, and go warning if not

–help - This help page

建立nagios监控用户
slave
服务器需要设置File/Process/Super权限,master服务器需要设置replication slave/replication client/super权限
mysql> grant file,process,super on *.* to nagios@’nagiosServerIP’ identified by ‘Vale.com-init’;
mysql> grant replication client,super on *.* to ‘nagios’@'nagiosServerIP’ identified by ‘Vale.com-init’;

测试
# /usr/local/nagios/libexec/check_mysql -H 192.168.0.100 -u nagios -p nagios
Uptime: 623338 Threads: 1 Questions: 5386477 Slow queries: 34 Opens: 198 Flush tables: 1 Open tables: 89 Queries per second avg: 8.641

# /usr/local/nagios/libexec/check_mysql_replication –slave 192.168.0.105 –slave-user nagios –slave-pass nagios –master 192.168.0.100 –master-user nagios –master-pass nagios
OK: 0.000 diff, 0 secs, 192.168.0.100:3306 (5.0.45-log) -> 192.168.0.105:3306 (5.0.40-log)

配置nagios监控
# /usr/local/nagios/etc/objects/comands.cfg
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -u nagios -p nagios
}

define command {
command_name check_mysql_replication
command_line $USER1R/check_mysql_replication –slave $ARG1$ –slave-user nagios –slave-pass nagios –master $ARG2$ –master-user nagios –master-pass nagios
}

# vi /usr/local/nagios/server/v-cdn.cfg
define service {
host_name ads01
service_description mysql
check_interval 30
retry_interval 18
max_check_attempts 5
check_period 24×7
check_command check_mysql!192.168.0.105
}

define service {
host_name ads01
service_description mysql_replication
check_interval 30
retry_interval 18
max_check_attempts 5
check_period 24×7
check_command check_mysql_replication!192.168.0.105!192.168.0.100
}

重启nagios服务,5分钟后,nagios测试状态成功!

公司CDN运营服务器要求监控squid服务状态,可以用nagios自带的check_http插件校验,check_http -H 目标主机域名 -p 80 -I 缓存服务器地址。
google寻找相关资料时,发现专门用于squid检测的nagios插件,用perl写的。

文档

安装
# cd /usr/local/nagios/libexec
# wget
# chown 755 check_squid

安装perl模块
如果缺少perl程序执行所依赖的模块,会出现以下的错误提示,请安装所需要的perl模块
# yum -y install perl-libwww-perl

check_squid命令参数
Usage: url urluser urlpass proxy proxyport proxyuser proxypass expectstatus
url squid dst
站点域名 如:
urluser
目标站点需要认证登录的用户名, 符号“-”代表没有
urlpass
目标站点需要认证登录的用户密码, 符号“-”代表没有
proxy squid cache
服务器的IP地址或者域名
proxyport Squid cache
服务器监听的端口,默认3128
proxyuser squid cache
服务器需要认证登录的用户名, 符号“-”代表没有
proxypass squid cache
服务器需要认证登录的用户名, 符号“-”代表没有
expectstatus HTTP
协议返回的HTTP code, 符号2”代表从2开始

测试
目标主机squid cache服务器111.111.111.111,监听端口80
#/usr/local/nagios/libexec/check_squid - - 111.111.111.111 80 - - 2
OK - Status: 200 OK

配置nagios监控
# /usr/local/nagios/etc/objects/comands.cfg
define command {
command_name check_squid
command_line $USER1$/check_squid $ARG1$ $ARG2$ $ARG3$ $HOSTADDRESS$ $ARG4$ $ARG5$ $ARG6$ $ARG7$
}

# vi /usr/local/nagios/server/v-cdn.cfg
define service {
hostgroup_name cdn-service
service_description squid
check_interval 30
retry_interval 18
max_check_attempts 5
check_period 24×7
check_command check_squid!!-!-!80!-!-!2
}

重启nagios服务,5分钟后测试状态成功!

 

 

 

阅读(1836) | 评论(0) | 转发(0) |
0

上一篇:Mysql同步延迟

下一篇:今日新闻2010-09-07

给主人留下些什么吧!~~