首页 > 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. 2017年11月30日16:17 | #1

    Can I just say what a comfort to find a person that genuinely understands what
    they’re discussing online. You certainly know how to bring a problem
    to light and make it important. More people really need to look at this and
    understand this side of your story. I was surprised that you are not more popular
    because you certainly have the gift.

  2. 2017年12月2日23:50 | #2

    Greate article. Keep writing such kind of info on your site.

    Im really impressed by your blog.
    Hey there, You’ve performed an excellent job. I will certainly digg it
    and for my part suggest to my friends. I am confident they will be benefited from this site.

  3. 2017年12月7日16:07 | #3

    I think the admin of this site is in fact working hard in favor of his site, as here
    every information is quality based data.

  4. 2017年12月17日21:16 | #4

    Thanks for a marvelous posting! I genuinely enjoyed reading it, you’re a great author.
    I will be sure to bookmark your blog and will come back someday.

    I want to encourage you to ultimately continue your great posts,
    have a nice day!

  5. 2017年12月29日13:20 | #5

    online casino
    real money casino
    free casino games
    real money casino
    casino games

  6. 2018年1月2日20:15 | #6

    download casino on net
    casino
    online blackjack legal united states

  7. 2018年1月3日06:42 | #7

    loans no credit check
    loans no credit
    payday loans
    payday loans online
    payday loans

  8. 2018年1月7日08:37 | #8

    free casino slot games
    free casino games slot
    free slots casino games
    slots casino
    freeslots

  9. 2018年1月10日22:57 | #9

    Good article! We are linking to this great post on our website.

    Keep up the great writing.

  10. 2018年1月15日01:15 | #10

    What’s up, its pleasant paragraph regarding media print,
    we all know media is a enormous source of facts.

  11. 2018年1月15日16:56 | #11

    Hi this is kind of of off topic but I was wanting to know if blogs
    use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding experience so
    I wanted to get guidance from someone with experience. Any help would
    be greatly appreciated!

  12. 2018年1月15日18:30 | #12

    loans no credit
    loans no credit check
    loans no credit
    loans for bad credit
    loans for bad credit

  13. 2018年1月19日22:33 | #13

    usa online slots real money
    casinos in west virginia
    free slots vegas world
    slots for money online
    us online casinos

评论分页
1 2 3 4 441
订阅评论
5+5= (必填)