From 23409cd63a74ddbf5a06816adff6bb3199b0b7a6 Mon Sep 17 00:00:00 2001 From: Todd Troxell Date: Sat, 21 Jul 2007 09:42:54 +0200 Subject: [PATCH] Initial version --- plugins/other/monit_parser | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 plugins/other/monit_parser diff --git a/plugins/other/monit_parser b/plugins/other/monit_parser new file mode 100755 index 00000000..5d34a3a3 --- /dev/null +++ b/plugins/other/monit_parser @@ -0,0 +1,61 @@ +#!/usr/bin/python +# Monit status parser plugin for munin + +# This is very raw, but it should work for you out of the box. You of course +# need to have monit configured such that the 'monit status' command works. + +# Todd Troxell + +STATUS_CMD = "monit status" + +import sys +import re +from commands import getstatusoutput + +def sanitize(s): + OK_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789" + out = str() + for char in s: + if char.lower() in OK_CHARS: + out += char + return out + +procs = dict() + +status, output = getstatusoutput(STATUS_CMD) +if status != 0: + print "Errror running status command: %s" % (output) + sys.exit(status) + +output = output.split('\n') +cur_proc = None +for line in output: + m = re.match("^Process '(.*)'.*$", line) + if m: + cur_proc = sanitize(m.group(1)) + try: + procs[cur_proc] + except KeyError: + procs[cur_proc] = dict() + continue + m = re.match(" memory kilobytes total\s+([0-9]+).*$", line) + if m: + procs[cur_proc]["total_memory"] = m.group(1) + continue + m = re.match(" cpu percent total\s+([.0-9]+)%.*$", line) + if m: + procs[cur_proc]["total_cpu"] = m.group(1) + continue + +if len(sys.argv) > 1 and sys.argv[1] == 'config': + print 'graph_title Per process stats from Monit' + print 'graph_vlabel numbers' + print 'graph_category monit' + for process in procs: + for stat in procs[process]: + print "monit_%s_%s.label %s.%s" % (process, stat, process, stat) + sys.exit(0) + +for process in procs: + for stat in procs[process]: + print "monit_%s_%s.value %s" % (process, stat, procs[process][stat])