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