2008-02-16 17:23:47 +01:00
|
|
|
#!/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:
|
|
|
|
#
|
2018-03-28 04:45:41 +02:00
|
|
|
# config (required)
|
|
|
|
# autoconf (optional - used by munin-config)
|
2008-02-16 17:23:47 +01:00
|
|
|
#
|
|
|
|
# Magic markers - optional - used by installation scripts and
|
|
|
|
# munin-config:
|
|
|
|
#
|
2018-03-28 04:45:41 +02:00
|
|
|
# #%# family=manual
|
|
|
|
# #%# capabilities=autoconf
|
2008-02-16 17:23:47 +01:00
|
|
|
#
|
|
|
|
# Now for the real work...
|
|
|
|
|
|
|
|
from os.path import walk, exists, isfile, join
|
2018-03-28 04:45:41 +02:00
|
|
|
from sys import argv, exit
|
2008-02-16 17:23:47 +01:00
|
|
|
|
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
def get_file_types():
|
|
|
|
"""Returns an array of filetype => count."""
|
|
|
|
out = {}
|
2008-02-16 17:23:47 +01:00
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
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
|
2008-02-16 17:23:47 +01:00
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
walk('/var/cache/approx/', visitor, None)
|
|
|
|
return out
|
2008-02-16 17:23:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
if len(argv) > 1:
|
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
# Autoconfiguration
|
|
|
|
if argv[1] == "autoconf":
|
|
|
|
# Test if we can find a approx cache
|
|
|
|
if exists('/var/cache/approx'):
|
|
|
|
print("yes")
|
|
|
|
else:
|
|
|
|
print("no ('/var/cache/approx' not found)")
|
|
|
|
exit()
|
2008-02-16 17:23:47 +01:00
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
elif argv[1] == "config":
|
|
|
|
print("graph_title Approx cache")
|
|
|
|
print("graph yes")
|
|
|
|
print("graph_category loadbalancer")
|
|
|
|
print("graph_info Statistics from the Approx cache.")
|
|
|
|
for filetype in get_file_types().keys():
|
|
|
|
print("%s.label %s" % (filetype.lower(), filetype))
|
|
|
|
exit()
|
2008-02-16 17:23:47 +01:00
|
|
|
|
2018-03-28 04:45:41 +02:00
|
|
|
for filetype, count in get_file_types().iteritems():
|
|
|
|
print("%s.value %d" % (filetype.lower(), count))
|
2008-02-16 17:23:47 +01:00
|
|
|
|
|
|
|
exit()
|