Linux下监控网页-Nagios(图)

运维 系统运维
Linux下监控网页-Nagios:Nagios是一个监视系统,它可以监视系统运行状态和网络信息。Nagios能监视所指定的本地、远程主机以及服务、异常通知等。本文讲述的是Linux下监控网页-Nagios。

  使用Nagios监控网页

  1. Nagios监控问题的由来

  对于一个网站来说,外部用户能够看到就是该网站的页面。网站页面能否被正常访问,以及显示是否正常势必会成为网站整体水平最直接的外在表现。

  那么,如何才能在***时间检测到网页是否正常,并且给相应的技术人员发出报警来及时解决问题,而不是等接到用户抱怨的电话后才在慌忙中仓促的解决问题呢?解决这个问题的关键就是要在***时间发现问题,发现那些不能显示的网页或是显示不正常的网页,并及时发出报警。当然我们可以通过人工的方法去监测,但对于一些大型的、复杂的网站来说就不是很合适了,我们可以使用监控软件来解决这个问题。我所使用的就是Nagios软件,它提供的插件(Plugins)中有相应的命令可以完成对网页的监控。

  2. 如何通过Nagios解决此类问题

  对于Nagios、NRPE以及Nagios Plugins的安装配置网站的资料很多,在我的Blog中也有相应的文章可以参考,在这里就不再过多的说明了。

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

  1.   Usage: check_http -H | -I [-u ] [-p ]  
  2.  
  3.   [-w ] [-c ] [-t ] [-L]  
  4.  
  5.   [-a auth] [-f ] [-e ]  
  6.  
  7.   [-s string] [-l] [-r | -R ] [-P string]  
  8.  
  9.   [-m :] [-4|-6] [-N] [-M ] [-A string]  
  10.  
  11.   [-k string] [-S] [-C ] [-T ]  
  12.  
  13.   NOTE: One or both of -H and -I must be specified  
  14.  
  15.   Options:  
  16.  
  17.   -h, --help  
  18.  
  19.   Print detailed help screen  
  20.  
  21.   -V, --version  
  22.  
  23.   Print version information  
  24.  
  25.   -H, --hostname=ADDRESS 
  26.  
  27.   Host name argument for servers using host headers (virtual host)  
  28.  
  29.   Append a port to include it in the header (eg: example.com:5000)  
  30.  
  31.   -I, --IP-address=ADDRESS 
  32.  
  33.   IP address or name (use numeric address if possible to bypass DNS lookup).  
  34.  
  35.   -p, --port=INTEGER 
  36.  
  37.   Port number (default: 80)  
  38.  
  39.   -4, --use-ipv4  
  40.  
  41.   Use IPv4 connection  
  42.  
  43.   -6, --use-ipv6  
  44.  
  45.   Use IPv6 connection  
  46.  
  47.   -S, --ssl  
  48.  
  49.   Connect via SSL. Port defaults to 443  
  50.  
  51.   -C, --certificate=INTEGER 
  52.  
  53.   Minimum number of days a certificate has to be valid. Port defaults to 443  
  54.  
  55.   (when this option is used the url is not checked.)  
  56.  
  57.   -e, --expect=STRING 
  58.  
  59.   String to expect in first (status) line of server response (default:  
  60.  
  61.   HTTP/1.)  
  62.  
  63.   If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)  
  64.  
  65.   -s, --string=STRING 
  66.  
  67.   String to expect in the content  
  68.  
  69.   -u, --url=PATH 
  70.  
  71.   URL to GET or POST (default: /)  
  72.  
  73.   -P, --post=STRING 
  74.  
  75.   URL encoded http POST data  
  76.  
  77.   -N, --no-body  
  78.  
  79.   Don’t wait for document body: stop reading after headers.  
  80.  
  81.   (Note that this still does an HTTP GET or POST, not a HEAD.)  
  82.  
  83.   -M, --max-age=SECONDS 
  84.  
  85.   Warn if document is more than SECONDS old. the number can also be of  
  86.  
  87.   the form "10m" for minutes, "10h" for hours, or "10d" for days.  
  88.  
  89.   -T, --content-type=STRING 
  90.  
  91.   specify Content-Type header media type when POSTing  
  92.  
  93.   -l, --linespan  
  94.  
  95.   Allow regex to span newlines (must precede -r or -R)  
  96.  
  97.   -r, --regex, --ereg=STRING 
  98.  
  99.   Search page for regex STRING  
  100.  
  101.   -R, --eregi=STRING 
  102.  
  103.   Search page for case-insensitive regex STRING  
  104.  
  105.   --invert-regex  
  106.  
  107.   Return CRITICAL if found, OK if not  
  108.  
  109.   -a, --authorization=AUTH_PAIR 
  110.  
  111.   Username:password on sites with basic authentication  
  112.  
  113.   -A, --useragent=STRING 
  114.  
  115.   String to be sent in http header as "User Agent"  
  116.  
  117.   -k, --header=STRING 
  118.  
  119.   Any other tags to be sent in http header. Use multiple times for additional headers  
  120.  
  121.   -L, --link  
  122.  
  123.   Wrap output in HTML link (obsoleted by urlize)  
  124.  
  125.   -f, --onredirect=  
  126.  
  127.   How to handle redirected pages  
  128.  
  129.   -m, --pagesize=INTEGER<:INTEGER> 
  130.  
  131.   Minimum page size required (bytes) : Maximum page size required (bytes)  
  132.  
  133.   -w, --warning=DOUBLE 
  134.  
  135.   Response time to result in warning status (seconds)  
  136.  
  137.   -c, --critical=DOUBLE 
  138.  
  139.   Response time to result in critical status (seconds)  
  140.  
  141.   -t, --timeout=INTEGER 
  142.  
  143.   Seconds before connection times out (default: 10)  
  144.  
  145.   -v, --verbose  
  146.  
  147.   Show details for command-line debugging (Nagios may truncate output)  
  148.  

  通过check_http的帮助我们可以清楚的了解到该命令可以为我们做什么,以及如何去做。选项虽然很多,其实常被用到的却只有几项,而且很多选项是有默认值的一般无需设置。下面就我们需要用到的几个选项做一个简要的说明。

   选项说明:

  -H, --hostname=ADDRESS主机名或域名

  -I, --IP-address=ADDRESSserver的IP地址,用于在不能DNS的情况下

  -p, --port=INTEGER端口号,默认80

  -u, --url=PATHurl,默认是/

  -w, --warning=DOUBLEwarning状态的响应时间,单位是秒

  -c, --critical=DOUBLEcritical状态的响应时间,单位是秒

  -t, --timeout=INTEGER连接超时时间,默认10秒

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

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

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

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

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

Nagios/监控 

  Linux下监控网页-Nagios就介绍到这里了,下一节:Linux下监控网页-NRPE

【编辑推荐】

Nagios飞信linux短信报警脚本配置

Nagios安装记录

如何用Nagios监控远程系统

 

责任编辑:zhaolei 来源: 青路网
相关推荐

2011-03-23 09:47:03

Nagios监控

2011-03-21 15:42:14

LinuxNagios

2011-03-23 12:44:06

Nagios监控

2011-03-21 14:53:27

Nagios监控Linux

2011-03-25 15:37:17

Solarisnagios

2011-03-22 09:03:47

Nagios配置

2011-03-24 13:00:22

CentOSNagios安装

2011-03-24 11:03:05

Nagios监控Linux

2014-09-28 10:37:45

LinuxNagiosNRPE

2011-03-21 11:14:22

LinuxNagios

2011-03-21 13:01:56

LinuxNagios安装

2011-04-06 14:24:20

Nagios监控Linux

2011-03-21 14:53:36

Nagios监控Linux

2011-03-21 14:53:27

Nagios监控Linux

2011-04-06 14:24:21

Nagios监控Linux

2011-03-22 09:07:13

Nagios监控Linux

2011-03-21 11:14:24

LinuxNagios

2011-03-04 10:47:06

Nagios监控Sphinx

2011-03-24 10:08:39

Nagios监控oracle

2011-04-06 14:24:28

nagios监控Linux
点赞
收藏

51CTO技术栈公众号