From e51defac8464d4ebaba62201d3af09388945bc89 Mon Sep 17 00:00:00 2001 From: Morten Siebuhr Date: Sat, 16 Feb 2008 17:23:47 +0100 Subject: [PATCH] Initial version --- plugins/other/approx | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 plugins/other/approx diff --git a/plugins/other/approx b/plugins/other/approx new file mode 100755 index 00000000..f2d4c253 --- /dev/null +++ b/plugins/other/approx @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# vim:syntax=python +# +# Plugin to monitor the amount of packages in an approx cache. +# +# Usage: place in /etc/munin/plugins/ (or link it there using ln -s) +# +# Parameters understood: +# +# config (required) +# autoconf (optional - used by munin-config) +# +# Magic markers - optional - used by installation scripts and +# munin-config: +# +#%# family=manual +#%# capabilities=autoconf +# +# Now for the real work... + +from sys import argv, exit +from os.path import walk, exists, isfile, join + +def get_file_types(): + """Returns an array of filetype => count.""" + + out = {} + + def visitor(arg, dirname, names): + for file in names: + if not isfile(join(dirname, file)): + continue + ext = file.split(".")[-1] + + out[ext] = out.get(ext, 0) + 1 + + walk('/var/cache/approx/', visitor, None) + + return out + + +# Autoconfiguration +if len(argv) > 1: + + if argv[1] == "autoconf": + # Test if we can find a approx cache + if exists('/var/cache/approx'): + print "yes" + else: + print "no ('/var/cacne/approx' not found)" + exit(1) + exit() + + elif argv[1] == "config": + print "graph_title Approx cache"; + print "graph yes"; + #print "graph_category Other"; + #print "graph_total Total"; + print "graph_info Statistics from the Approx cache."; + #print "debs.label DEBs"; + #print "pending.warning 0:0"; + #print "hold.label hold"; + for type in get_file_types().keys(): + print "%s.label %s" % (type.lower(), type) + exit() + +for type, count in get_file_types().iteritems(): + print "%s.value %d" % (type.lower(), count) + +exit()