mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 18:38:30 +00:00
Merge pull request #158 from ndonegan/imapproxy
Added in an imapproxy plugin
This commit is contained in:
commit
cf64117ba9
1 changed files with 153 additions and 0 deletions
153
plugins/mail/imapproxy_
Executable file
153
plugins/mail/imapproxy_
Executable file
|
@ -0,0 +1,153 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""=cut
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
imapproxy - Munin Plugin to monitor imapproxy using pimpstat
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
This plugin should require no addition configuration.
|
||||||
|
|
||||||
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
|
#%# family=auto
|
||||||
|
#%# capabilities=autoconf suggest
|
||||||
|
|
||||||
|
=head1 Author
|
||||||
|
|
||||||
|
Niall Donegan <github@nialldonegan.me>
|
||||||
|
|
||||||
|
=head1 LICENSE
|
||||||
|
|
||||||
|
GPLv2
|
||||||
|
|
||||||
|
=cut"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from subprocess import Popen,PIPE
|
||||||
|
|
||||||
|
|
||||||
|
def print_autoconf():
|
||||||
|
which = Popen("which pimpstat", shell=True, stdout=PIPE)
|
||||||
|
which.communicate()
|
||||||
|
if not bool(which.returncode):
|
||||||
|
print "yes"
|
||||||
|
else:
|
||||||
|
print "no (pimpstat not found)"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def print_config(graph):
|
||||||
|
if graph == "cache":
|
||||||
|
print "graph_title Cache Statistics For ImapProxy"
|
||||||
|
print "graph_args -l 0 --base 1000"
|
||||||
|
print "graph_total total"
|
||||||
|
print "graph_vlabel Cache Connections / ${graph_period}"
|
||||||
|
print "graph_category imapproxy"
|
||||||
|
print "cache_hits.draw AREA"
|
||||||
|
print "cache_hits.type DERIVE"
|
||||||
|
print "cache_hits.label Cache Hits"
|
||||||
|
print "cache_hits.min 0"
|
||||||
|
print "cache_misses.draw STACK"
|
||||||
|
print "cache_misses.type DERIVE"
|
||||||
|
print "cache_misses.label Cache Misses"
|
||||||
|
print "cache_misses.min 0"
|
||||||
|
if graph == "connections":
|
||||||
|
print "graph_title Connection Statistics For ImapProxy"
|
||||||
|
print "graph_args -l 0 --base 1000"
|
||||||
|
print "graph_total total"
|
||||||
|
print "graph_vlabel Connections / ${graph_period}"
|
||||||
|
print "graph_category imapproxy"
|
||||||
|
print "connections_reused.draw AREA"
|
||||||
|
print "connections_reused.type DERIVE"
|
||||||
|
print "connections_reused.label Reused Connections"
|
||||||
|
print "connections_reused.min 0"
|
||||||
|
print "connections_created.draw STACK"
|
||||||
|
print "connections_created.type DERIVE"
|
||||||
|
print "connections_created.label Created Connections"
|
||||||
|
print "connections_created.min 0"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def print_suggest():
|
||||||
|
print "cache"
|
||||||
|
print "connections"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def print_fetch(graph):
|
||||||
|
if graph == "cache":
|
||||||
|
hits = 0
|
||||||
|
misses = 0
|
||||||
|
cache = Popen(
|
||||||
|
"pimpstat -c | egrep 'Cache (Hits|Misses)'",
|
||||||
|
shell=True,
|
||||||
|
stdout=PIPE
|
||||||
|
)
|
||||||
|
for line in cache.stdout:
|
||||||
|
if re.search(r'Hits', line):
|
||||||
|
hits = line.split()[0]
|
||||||
|
if re.search(r'Misses', line):
|
||||||
|
misses = line.split()[0]
|
||||||
|
print "cache_hits.value %s" % hits
|
||||||
|
print "cache_misses.value %s" % misses
|
||||||
|
if graph == "connections":
|
||||||
|
created = 0
|
||||||
|
reused = 0
|
||||||
|
connections = Popen(
|
||||||
|
"pimpstat -c | egrep 'Total (Reused|Created)'",
|
||||||
|
shell=True,
|
||||||
|
stdout=PIPE
|
||||||
|
)
|
||||||
|
for line in connections.stdout:
|
||||||
|
if re.search(r'Created', line):
|
||||||
|
created = line.split()[0]
|
||||||
|
if re.search(r'Reused', line):
|
||||||
|
reused = line.split()[0]
|
||||||
|
print "connections_created.value %s" % created
|
||||||
|
print "connections_reused.value %s" % resused
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
basename = "imapproxy_"
|
||||||
|
calledname = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
command = sys.argv[1]
|
||||||
|
else:
|
||||||
|
command = "fetch"
|
||||||
|
|
||||||
|
if calledname == basename and command == "fetch":
|
||||||
|
print >> sys.stderr, "Please use either suggest or autoconf"
|
||||||
|
sys.exit(1)
|
||||||
|
if calledname == basename and command not in ["autoconf","suggest"]:
|
||||||
|
print >> sys.stderr, "Command %s not known, please use either autoconf or suggest" % command
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
graph = calledname[calledname.find("_")+1:]
|
||||||
|
if calledname != basename and graph not in ["cache","connections"]:
|
||||||
|
print >> sys.stderr, "%s is not a known graph" % graph
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if calledname != basename and command not in ["config", "fetch"]:
|
||||||
|
print >> sys.stderr, "Command %s not known, please use either config or fetch" % command
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if command == "autoconf":
|
||||||
|
print_autoconf()
|
||||||
|
elif command == "config":
|
||||||
|
print_config(graph)
|
||||||
|
elif command =="suggest":
|
||||||
|
print_suggest()
|
||||||
|
else:
|
||||||
|
print_fetch(graph)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
# vim:syntax=python
|
Loading…
Add table
Add a link
Reference in a new issue