root / plugins / lighttpd / lighttpd_ @ ef960abc
Historique | Voir | Annoter | Télécharger (3,47 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# vim: set fileencoding=utf-8 |
| 4 |
# |
| 5 |
# Munin plugin to monitor lighttpd web-server. |
| 6 |
# |
| 7 |
# Copyright Igor Borodikhin |
| 8 |
# |
| 9 |
# License : GPLv3 |
| 10 |
# |
| 11 |
# Configuration parameters: |
| 12 |
# env.status_url - url of lighty's server-status (optional, default is http://127.0.0.1/server-status) |
| 13 |
# env.username - username to provide if status_url requires basic authentication (optional, default - no authentication) |
| 14 |
# env.password - password to provide if status_url requires basic authentication (optional, default - no authentication) |
| 15 |
# |
| 16 |
# Note: If basic HTTP authentication is required you should specify both username and password. |
| 17 |
# |
| 18 |
# ## Installation |
| 19 |
# Copy file to directory /usr/share/munin/plugins/ |
| 20 |
# Because this plugin has suggest capability the last step is to run |
| 21 |
# # munin-node-configure --suggest --shell | sh -x |
| 22 |
# |
| 23 |
#%# family=contrib |
| 24 |
#%# capabilities=autoconf suggest |
| 25 |
|
| 26 |
import os, sys, urllib2, base64 |
| 27 |
|
| 28 |
program = sys.argv[0] |
| 29 |
graph_type = program[program.rfind("_")+1:]
|
| 30 |
graph_types = {
|
| 31 |
"accesses" : [ |
| 32 |
{
|
| 33 |
"title" : "Total accesses", |
| 34 |
"type" : "COUNTER", |
| 35 |
"args" : "--base 1000 -l 0", |
| 36 |
"fields" : ["accesses"] |
| 37 |
} |
| 38 |
], |
| 39 |
"kbytes" : [ |
| 40 |
{
|
| 41 |
"title" : "Total kBytes", |
| 42 |
"type" : "COUNTER", |
| 43 |
"args" : "--base 1024 -l 0", |
| 44 |
"fields" : ["kbytes"] |
| 45 |
} |
| 46 |
], |
| 47 |
"uptime" : [ |
| 48 |
{
|
| 49 |
"title" : "Uptime", |
| 50 |
"type" : "GAUGE", |
| 51 |
"args" : "--base 1000 -l 0", |
| 52 |
"fields" : ["uptime"] |
| 53 |
} |
| 54 |
], |
| 55 |
"status" : [ |
| 56 |
{
|
| 57 |
"title" : "Status", |
| 58 |
"type" : "GAUGE", |
| 59 |
"args" : "--base 1000 -l 0", |
| 60 |
"fields" : ["busy", "idle"] |
| 61 |
} |
| 62 |
] |
| 63 |
} |
| 64 |
|
| 65 |
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
| 66 |
print "yes" |
| 67 |
elif len(sys.argv) == 2 and sys.argv[1] == "config": |
| 68 |
if graph_type not in graph_types.keys(): |
| 69 |
raise Exception("Unknown graph type '%s'"%graph_type)
|
| 70 |
params = graph_types[graph_type] |
| 71 |
for item in params: |
| 72 |
print "graph_title %s" % item["title"] |
| 73 |
print "graph_category lighttpd" |
| 74 |
for field in item["fields"]: |
| 75 |
print "%s.label %s" % (field, field) |
| 76 |
print "%s.type %s" % (field, item["type"]) |
| 77 |
print "graph_args %s" % item["args"] |
| 78 |
elif len(sys.argv) == 2 and sys.argv[1] == "suggest": |
| 79 |
for item in graph_types.keys(): |
| 80 |
print item |
| 81 |
else: |
| 82 |
if "status-url" not in os.environ: |
| 83 |
status_url = "http://127.0.0.1/server-status" |
| 84 |
else: |
| 85 |
status_url = os.environ["status_url"] |
| 86 |
|
| 87 |
request = urllib2.Request("%s?auto" % status_url)
|
| 88 |
if "username" in os.environ and "password" in os.environ: |
| 89 |
base64str = base64.encodestring("%s:%s" % (os.environ["username"], os.environ["password"])).replace("\r", "")
|
| 90 |
request.add_header("Authorization", "Basic %s" % base64str)
|
| 91 |
info = urllib2.urlopen(request).read() |
| 92 |
data = {}
|
| 93 |
lines = info.split("\n")
|
| 94 |
for line in lines: |
| 95 |
try: |
| 96 |
(title, value) = line.split(": ")
|
| 97 |
data[title] = value |
| 98 |
except Exception: |
| 99 |
pass |
| 100 |
|
| 101 |
if graph_type == "accesses": |
| 102 |
print "accesses.value %s" % data["Total Accesses"] |
| 103 |
elif graph_type == "kbytes": |
| 104 |
print "kbytes.value %s" % data["Total kBytes"] |
| 105 |
elif graph_type == "uptime": |
| 106 |
print "uptime.value %s" % str(float(data["Uptime"])/86400) |
| 107 |
elif graph_type == "status": |
| 108 |
print "busy.value %s" % data["BusyServers"] |
| 109 |
print "idle.value %s" % data["IdleServers"] |
