Skip to content

Instantly share code, notes, and snippets.

@peterfroehlich
Created November 14, 2013 10:58
Show Gist options
  • Save peterfroehlich/7464949 to your computer and use it in GitHub Desktop.
Save peterfroehlich/7464949 to your computer and use it in GitHub Desktop.
Generic munin shell cmd monitor replace monitor_cmd with your shell cmd
#!/usr/bin/env python
# munin-deleted-files.py
#
# Generic munin shell cmd monitor
# replace monitor_cmd with your shell cmd
#
from sys import exit,argv
import subprocess
##### Config #####
monitorprefix = "DelFiles"
host = "host"
monitor_cmd = "lsof | grep deleted | wc -l"
##################
def showconfig():
# print 'host_name '+host
print "graph_title "+monitorprefix
print "graph_info Generated by munin-deleted-files.py script"
print "graph_category disk"
print "graph_scale yes"
print monitorprefix+".label Nr"
print monitorprefix+".info Number of open deleted filehandles"
exit(0)
debug = 0
# Validate parameters
if len(argv[:]) > 1:
if argv[1] == "config":
showconfig()
elif argv[1] == "debug" or argv[1] == "-d":
debug = 1
else:
print "Unknown parameter."
exit(1)
nr_of_procs = monitor_cmd.count("|")
for proc_part in range(0,nr_of_procs+1):
cmd = monitor_cmd.split("|")[proc_part].strip()
if debug == 1:
print str(proc_part)+": "+cmd
if proc_part == 0:
p = subprocess.Popen(cmd.split(" "), stdout=subprocess.PIPE)
value, err = p.communicate()
else:
p = subprocess.Popen(cmd.split(" "), stdin = subprocess.PIPE, stdout = subprocess.PIPE)
p.stdin.write(value)
value, err = p.communicate()
print monitorprefix+".value "+str(value).strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment