Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / approx @ 7da1b039

Historique | Voir | Annoter | Télécharger (1,5 ko)

1 e51defac Morten Siebuhr
#!/usr/bin/env python
2
#
3
# vim:syntax=python
4
#
5
# Plugin to monitor the amount of packages in an approx cache.
6
#
7
# Usage: place in /etc/munin/plugins/ (or link it there using ln -s)
8
#
9
# Parameters understood:
10
#
11
# 	config   (required)
12
# 	autoconf (optional - used by munin-config)
13
#
14
# Magic markers - optional - used by installation scripts and
15
# munin-config:
16
#
17
#%# family=manual
18
#%# capabilities=autoconf
19
#
20
# Now for the real work...
21
22
from sys import argv, exit
23
from os.path import walk, exists, isfile, join
24
25
def get_file_types():
26
	"""Returns an array of filetype => count."""
27
28
	out = {}
29
30
	def visitor(arg, dirname, names):
31
		for file in names:
32
			if not isfile(join(dirname, file)):
33
				continue
34
			ext = file.split(".")[-1]
35
36
			out[ext] = out.get(ext, 0) + 1
37
38
	walk('/var/cache/approx/', visitor, None)
39
40
	return out
41
42
43
# Autoconfiguration
44
if len(argv) > 1:
45
46
	if argv[1] == "autoconf":
47
		# Test if we can find a approx cache
48
		if exists('/var/cache/approx'):
49
			print "yes"
50
		else:
51
			print "no ('/var/cacne/approx' not found)"
52
			exit(1)
53
		exit()
54
55
	elif argv[1] == "config":
56
		print "graph_title Approx cache";
57
		print "graph yes";
58
		#print "graph_category Other";
59
		#print "graph_total Total";
60
		print "graph_info Statistics from the Approx cache.";
61
		#print "debs.label DEBs";
62
		#print "pending.warning 0:0";
63
		#print "hold.label hold";
64
		for type in get_file_types().keys():
65
			print "%s.label %s" % (type.lower(), type)
66
		exit()
67
68
for type, count in get_file_types().iteritems():
69
	print "%s.value %d" % (type.lower(), count)
70
71
exit()