首页 > nginx > 更新check_nginx插件

更新check_nginx插件

2011年1月25日 eric 发表评论 阅读评论

新增功能:

支持nginx BasicAuth 认证功能,
去掉了显示:serveraccepts handled requests
只显示主要的: ActiveConn reading writing waiting
优化代码可以省去不需要的参数。

源码:

# -*- coding: utf-8 -*-
#!/usr/bin/python
# check_nginx is a Nagios to monitor nginx statu
# my blog: http://www.nginxs.com
# The version is 1.0.1
# MSN: yangzi2008@126.com

import string
import urllib2
import getopt
import sys

def usage():
   print """check_nginx is a Nagios to monitor nginx status
   Usage:

   check_nginx [-h|--help][-U|--url][-P|--path][-u|--user][-p|--passwd][-w|--warning][-c|--critical]

   Options:
          --help|-h)
            print check_nginx help.
          --url|-U)
            Sets nginx status url.
          --path|-P)
            Sets nginx status url path. Default is: off
          --user|-u)
            Sets nginx status BasicAuth user. Default is: off
          --passwd|-p)
            Sets nginx status BasicAuth passwd. Default is: off
          --warning|-w)
            Sets a warning level for nginx Active connections. Default is: off
          --critical|-c)
            Sets a critical level for nginx Active connections. Default is: off
        Example:
            The url is www.nginxs.com/status
            ./check_nginx -U www.nginxs.com -P /status -u eric -p nginx -w 1000 -c 2000
            if dont't have password:
            ./check_nginx -U www.nginxs.com -P /status -w 1000 -c 2000
            if don't have path and password:
            ./check_nginx -U www.nginxs.com -w 1000 -c 2000"""

   sys.exit(3)

try:
    options,args = getopt.getopt(sys.argv[1:],"hU:P:u:p:w:c:",["help","url=","path=","user=","passwd=","warning=","critical="])

except getopt.GetoptError:
   usage()
   sys.exit(3)

for name,value in options:
    if name in ("-h","--help"):
       usage()
    if name in ("-U","--url"):
       url = "http://"+value
    if name in ("-P","--path"):
       path = value
    if name in ("-u","--user"):
       user = value
    if name in ("-p","--passwd"):
       passwd = value
    if name in ("-w","--warning"):
       warning = value
    if name in ("-c","--critical"):
       critical = value
try:
   if 'path' in dir():
      req = urllib2.Request(url+path)
   else:
      req = urllib2.Request(url)
   if 'user' in dir() and 'passwd' in dir():
      passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
      passman.add_password(None, url+path, user, passwd)
      authhandler = urllib2.HTTPBasicAuthHandler(passman)
      opener = urllib2.build_opener(authhandler)
      urllib2.install_opener(opener)
   response = urllib2.urlopen(req)
   the_page = response.readline()
   conn = the_page.split()
   ActiveConn = conn[2]
   the_page1 = response.readline()
   the_page2 = response.readline()
   the_page3 = response.readline()
   response.close()
   b = the_page3.split()
   reading = b[1]
   writing = b[3]
   waiting = b[5]
   output = 'ActiveConn:%s,reading:%s,writing:%s,waiting:%s' % (ActiveConn,reading,writing,waiting)
   perfdata = 'ActiveConn:%s,reading:%s,writing:%s,waiting:%s' % (ActiveConn,reading,writing,waiting)

except Exception:
   print "NGINX STATUS unknown: Error while getting Connection"
   sys.exit(3)
if 'warning' in dir() and 'critical' in dir():
   if ActiveConn >= warning:
      print 'WARNING - %s|%s' % (output,perfdata)
      sys.exit(2)
   elif ActiveConn >= critical:
      print 'CRITICAL - %s|%s' % (output,perfdata)
      sys.exit(1)
   else:
      print 'OK - %s|%s' % (output,perfdata)
      sys.exit(0)
else:
   print 'OK - %s|%s' % (output,perfdata)
   sys.exit(0)

使用方法:

./check_nginx -U www.nginxs.com -P /status -ueric -pnginx
OK - ActiveConn:1,reading:0,writing:1,waiting:0|ActiveConn:1,reading:0,writing:1,waiting:0
./check_nginx -U stat.nginxs.com
OK - ActiveConn:1,reading:0,writing:1,waiting:0|ActiveConn:1,reading:0,writing:1,waiting:0

下载连接:
check_nginx

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/441.html

分类: nginx 标签: ,
  1. 2011年1月27日10:16 | #1

    你的博文真好,虽然有许多我看不大懂!

  2. Tercel
    2011年7月7日16:47 | #2

    你好,咨询一下,我在FreeBSD运行这个脚本怎么出现import: command not found python这个已经安装了的

  3. 2018年4月4日05:55 | #3

    Such vehicles are already heading for the road.

  4. 2018年4月4日10:23 | #4

    Oil tank elimination in NY or CT doesn’t take long.

  5. 2018年4月4日20:54 | #5

    My Bryant ninety Plus furnace is not heating.

  6. 2018年4月7日14:50 | #6

    Use adhesive remover to take away the flooring adhesive.

  7. 2018年4月10日23:43 | #7

    How do you know it’s time to refinish the floor?

  8. 2018年4月11日09:50 | #8

    Fasteners tear the paper on ground sanders.

  9. 2018年4月13日17:31 | #9

    Take away Mold From Just about Any Surface.

  10. 2018年4月14日13:33 | #10

    Black Mould Clear up can a be a difficult activity.

  11. 2018年4月14日16:29 | #11

    That techniques is dustless refinishing.

  12. 2018年4月15日20:03 | #12

    Mold can be present in carpet and in the air.

  13. 2018年4月16日04:27 | #13

    You don’t have to make use of a mould killing product.

  14. 2018年4月16日16:48 | #14

    Polished concrete floors have few disadvantages.

  15. 2018年4月19日00:15 | #15

    That strategies is dustless refinishing.

  16. 2018年4月19日22:22 | #16

    Basement waterproofing takes some evaluation first.

  17. 2018年4月22日20:47 | #17

    Arborists will try to save damaged or diseased bushes.

  18. 2018年4月23日22:40 | #18

    Not all films are appropriate for all glass.

  19. 2018年4月24日03:56 | #19

    Arborists will attempt to save broken or diseased bushes.

订阅评论
2+5= (必填)