root / plugins / imapproxy / imapproxy_ @ 958f6a19
Historique | Voir | Annoter | Télécharger (4,17 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
"""=cut |
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
imapproxy - Munin Plugin to monitor imapproxy using pimpstat |
| 7 |
|
| 8 |
=head1 CONFIGURATION |
| 9 |
|
| 10 |
This plugin should require no addition configuration. |
| 11 |
|
| 12 |
=head1 MAGIC MARKERS |
| 13 |
|
| 14 |
#%# family=auto |
| 15 |
#%# capabilities=autoconf suggest |
| 16 |
|
| 17 |
=head1 Author |
| 18 |
|
| 19 |
Niall Donegan <github@nialldonegan.me> |
| 20 |
|
| 21 |
=head1 LICENSE |
| 22 |
|
| 23 |
GPLv2 |
| 24 |
|
| 25 |
=cut""" |
| 26 |
|
| 27 |
import sys |
| 28 |
import os |
| 29 |
import re |
| 30 |
from subprocess import Popen,PIPE |
| 31 |
|
| 32 |
|
| 33 |
def print_autoconf(): |
| 34 |
which = Popen("which pimpstat", shell=True, stdout=PIPE)
|
| 35 |
which.communicate() |
| 36 |
if not bool(which.returncode): |
| 37 |
print "yes" |
| 38 |
else: |
| 39 |
print "no (pimpstat not found)" |
| 40 |
sys.exit(0) |
| 41 |
|
| 42 |
|
| 43 |
def print_config(graph): |
| 44 |
if graph == "cache": |
| 45 |
print "graph_title Cache Statistics For ImapProxy" |
| 46 |
print "graph_args -l 0 --base 1000" |
| 47 |
print "graph_total total" |
| 48 |
print "graph_vlabel Cache Connections / ${graph_period}"
|
| 49 |
print "graph_category imapproxy" |
| 50 |
print "cache_hits.draw AREA" |
| 51 |
print "cache_hits.type DERIVE" |
| 52 |
print "cache_hits.label Cache Hits" |
| 53 |
print "cache_hits.min 0" |
| 54 |
print "cache_misses.draw STACK" |
| 55 |
print "cache_misses.type DERIVE" |
| 56 |
print "cache_misses.label Cache Misses" |
| 57 |
print "cache_misses.min 0" |
| 58 |
if graph == "connections": |
| 59 |
print "graph_title Connection Statistics For ImapProxy" |
| 60 |
print "graph_args -l 0 --base 1000" |
| 61 |
print "graph_total total" |
| 62 |
print "graph_vlabel Connections / ${graph_period}"
|
| 63 |
print "graph_category imapproxy" |
| 64 |
print "connections_reused.draw AREA" |
| 65 |
print "connections_reused.type DERIVE" |
| 66 |
print "connections_reused.label Reused Connections" |
| 67 |
print "connections_reused.min 0" |
| 68 |
print "connections_created.draw STACK" |
| 69 |
print "connections_created.type DERIVE" |
| 70 |
print "connections_created.label Created Connections" |
| 71 |
print "connections_created.min 0" |
| 72 |
sys.exit(0) |
| 73 |
|
| 74 |
|
| 75 |
def print_suggest(): |
| 76 |
print "cache" |
| 77 |
print "connections" |
| 78 |
sys.exit(0) |
| 79 |
|
| 80 |
def print_fetch(graph): |
| 81 |
if graph == "cache": |
| 82 |
hits = 0 |
| 83 |
misses = 0 |
| 84 |
cache = Popen( |
| 85 |
"pimpstat -c | egrep 'Cache (Hits|Misses)'", |
| 86 |
shell=True, |
| 87 |
stdout=PIPE |
| 88 |
) |
| 89 |
for line in cache.stdout: |
| 90 |
if re.search(r'Hits', line): |
| 91 |
hits = line.split()[0] |
| 92 |
if re.search(r'Misses', line): |
| 93 |
misses = line.split()[0] |
| 94 |
print "cache_hits.value %s" % hits |
| 95 |
print "cache_misses.value %s" % misses |
| 96 |
if graph == "connections": |
| 97 |
created = 0 |
| 98 |
reused = 0 |
| 99 |
connections = Popen( |
| 100 |
"pimpstat -c | egrep 'Total (Reused|Created)'", |
| 101 |
shell=True, |
| 102 |
stdout=PIPE |
| 103 |
) |
| 104 |
for line in connections.stdout: |
| 105 |
if re.search(r'Created', line): |
| 106 |
created = line.split()[0] |
| 107 |
if re.search(r'Reused', line): |
| 108 |
reused = line.split()[0] |
| 109 |
print "connections_created.value %s" % created |
| 110 |
print "connections_reused.value %s" % resused |
| 111 |
|
| 112 |
sys.exit(0) |
| 113 |
|
| 114 |
def main(): |
| 115 |
basename = "imapproxy_" |
| 116 |
calledname = os.path.basename(sys.argv[0]) |
| 117 |
|
| 118 |
if len(sys.argv) > 1: |
| 119 |
command = sys.argv[1] |
| 120 |
else: |
| 121 |
command = "fetch" |
| 122 |
|
| 123 |
if calledname == basename and command == "fetch": |
| 124 |
print >> sys.stderr, "Please use either suggest or autoconf" |
| 125 |
sys.exit(1) |
| 126 |
if calledname == basename and command not in ["autoconf","suggest"]: |
| 127 |
print >> sys.stderr, "Command %s not known, please use either autoconf or suggest" % command |
| 128 |
sys.exit(1) |
| 129 |
|
| 130 |
|
| 131 |
graph = calledname[calledname.find("_")+1:]
|
| 132 |
if calledname != basename and graph not in ["cache","connections"]: |
| 133 |
print >> sys.stderr, "%s is not a known graph" % graph |
| 134 |
sys.exit(1) |
| 135 |
|
| 136 |
if calledname != basename and command not in ["config", "fetch"]: |
| 137 |
print >> sys.stderr, "Command %s not known, please use either config or fetch" % command |
| 138 |
sys.exit(1) |
| 139 |
|
| 140 |
if command == "autoconf": |
| 141 |
print_autoconf() |
| 142 |
elif command == "config": |
| 143 |
print_config(graph) |
| 144 |
elif command =="suggest": |
| 145 |
print_suggest() |
| 146 |
else: |
| 147 |
print_fetch(graph) |
| 148 |
|
| 149 |
|
| 150 |
if __name__ == '__main__': |
| 151 |
main() |
| 152 |
|
| 153 |
# vim:syntax=python |
