1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-09-19 00:53:19 +00:00

plugin approx: various improvements

* python3 compatibility
* return zero autoconf exitcode
* avoid builtin names for variables
* remove cruft comments
* switch to space instead of tabs

All PEP8 issues are fixed now.
This commit is contained in:
Lars Kruse 2018-03-28 04:45:41 +02:00
parent 78d372adf4
commit 8d48cab125

View file

@ -8,64 +8,57 @@
# #
# Parameters understood: # Parameters understood:
# #
# config (required) # config (required)
# autoconf (optional - used by munin-config) # autoconf (optional - used by munin-config)
# #
# Magic markers - optional - used by installation scripts and # Magic markers - optional - used by installation scripts and
# munin-config: # munin-config:
# #
#%# family=manual # #%# family=manual
#%# capabilities=autoconf # #%# capabilities=autoconf
# #
# Now for the real work... # Now for the real work...
from sys import argv, exit
from os.path import walk, exists, isfile, join from os.path import walk, exists, isfile, join
from sys import argv, exit
def get_file_types(): def get_file_types():
"""Returns an array of filetype => count.""" """Returns an array of filetype => count."""
out = {}
out = {} def visitor(arg, dirname, names):
for filename in names:
if not isfile(join(dirname, filename)):
continue
ext = filename.split(".")[-1].lower()
out[ext] = out.get(ext, 0) + 1
def visitor(arg, dirname, names): walk('/var/cache/approx/', visitor, None)
for file in names: return out
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 len(argv) > 1:
if argv[1] == "autoconf": # Autoconfiguration
# Test if we can find a approx cache if argv[1] == "autoconf":
if exists('/var/cache/approx'): # Test if we can find a approx cache
print "yes" if exists('/var/cache/approx'):
else: print("yes")
print "no ('/var/cacne/approx' not found)" else:
exit(1) print("no ('/var/cache/approx' not found)")
exit() exit()
elif argv[1] == "config": elif argv[1] == "config":
print "graph_title Approx cache"; print("graph_title Approx cache")
print "graph yes"; print("graph yes")
#print "graph_category Other"; print("graph_category loadbalancer")
#print "graph_total Total"; print("graph_info Statistics from the Approx cache.")
print "graph_info Statistics from the Approx cache."; for filetype in get_file_types().keys():
#print "debs.label DEBs"; print("%s.label %s" % (filetype.lower(), filetype))
#print "pending.warning 0:0"; exit()
#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(): for filetype, count in get_file_types().iteritems():
print "%s.value %d" % (type.lower(), count) print("%s.value %d" % (filetype.lower(), count))
exit() exit()