root / plugins / monit / monit_parser @ 430d68ff
Historique | Voir | Annoter | Télécharger (1,61 ko)
| 1 | 23409cd6 | Todd Troxell | #!/usr/bin/python |
|---|---|---|---|
| 2 | # Monit status parser plugin for munin |
||
| 3 | |||
| 4 | # This is very raw, but it should work for you out of the box. You of course |
||
| 5 | # need to have monit configured such that the 'monit status' command works. |
||
| 6 | |||
| 7 | # Todd Troxell <ttroxell@debian.org> |
||
| 8 | |||
| 9 | STATUS_CMD = "monit status" |
||
| 10 | |||
| 11 | import sys |
||
| 12 | import re |
||
| 13 | from commands import getstatusoutput |
||
| 14 | |||
| 15 | def sanitize(s): |
||
| 16 | OK_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789" |
||
| 17 | out = str() |
||
| 18 | for char in s: |
||
| 19 | if char.lower() in OK_CHARS: |
||
| 20 | out += char |
||
| 21 | return out |
||
| 22 | |||
| 23 | procs = dict() |
||
| 24 | |||
| 25 | status, output = getstatusoutput(STATUS_CMD) |
||
| 26 | if status != 0: |
||
| 27 | print "Errror running status command: %s" % (output) |
||
| 28 | sys.exit(status) |
||
| 29 | |||
| 30 | output = output.split('\n')
|
||
| 31 | cur_proc = None |
||
| 32 | for line in output: |
||
| 33 | m = re.match("^Process '(.*)'.*$", line)
|
||
| 34 | if m: |
||
| 35 | cur_proc = sanitize(m.group(1)) |
||
| 36 | try: |
||
| 37 | procs[cur_proc] |
||
| 38 | except KeyError: |
||
| 39 | procs[cur_proc] = dict() |
||
| 40 | continue |
||
| 41 | m = re.match(" memory kilobytes total\s+([0-9]+).*$", line)
|
||
| 42 | if m: |
||
| 43 | procs[cur_proc]["total_memory"] = m.group(1) |
||
| 44 | continue |
||
| 45 | m = re.match(" cpu percent total\s+([.0-9]+)%.*$", line)
|
||
| 46 | if m: |
||
| 47 | procs[cur_proc]["total_cpu"] = m.group(1) |
||
| 48 | continue |
||
| 49 | |||
| 50 | if len(sys.argv) > 1 and sys.argv[1] == 'config': |
||
| 51 | print 'graph_title Per process stats from Monit' |
||
| 52 | print 'graph_vlabel numbers' |
||
| 53 | print 'graph_category monit' |
||
| 54 | for process in procs: |
||
| 55 | for stat in procs[process]: |
||
| 56 | print "monit_%s_%s.label %s.%s" % (process, stat, process, stat) |
||
| 57 | sys.exit(0) |
||
| 58 | |||
| 59 | for process in procs: |
||
| 60 | for stat in procs[process]: |
||
| 61 | print "monit_%s_%s.value %s" % (process, stat, procs[process][stat]) |
