Projet

Général

Profil

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

root / plugins / apt / approx @ e7e8ff99

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

1
#!/usr/bin/env python3
2
"""
3
=head1 NAME
4

    
5
approx - monitor the amount of packages in an approx cache
6

    
7

    
8
=head1 CONFIGURATION
9

    
10
Usage: place in /etc/munin/plugins/ (or link it there using ln -s)
11

    
12
Parameters understood:
13

    
14
 config   (required)
15
 autoconf (optional - used by munin-config)
16

    
17

    
18
=head1 AUTHORS
19

    
20
Copyright 2008 Morten Siebuhr <unknown@munin-monitoring.org>
21

    
22

    
23
=head1 MAGIC MARKERS
24

    
25
 #%# family=manual
26
 #%# capabilities=autoconf
27

    
28
=cut
29
"""
30

    
31
from os.path import walk, exists, isfile, join
32
from sys import argv, exit
33

    
34

    
35
def get_file_types():
36
    """Returns an array of filetype => count."""
37
    out = {}
38

    
39
    def visitor(arg, dirname, names):
40
        for filename in names:
41
            if not isfile(join(dirname, filename)):
42
                continue
43
            ext = filename.split(".")[-1].lower()
44
            out[ext] = out.get(ext, 0) + 1
45

    
46
    walk('/var/cache/approx/', visitor, None)
47
    return out
48

    
49

    
50
if len(argv) > 1:
51

    
52
    # Autoconfiguration
53
    if argv[1] == "autoconf":
54
        # Test if we can find a approx cache
55
        if exists('/var/cache/approx'):
56
            print("yes")
57
        else:
58
            print("no ('/var/cache/approx' not found)")
59
        exit()
60

    
61
    elif argv[1] == "config":
62
        print("graph_title Approx cache")
63
        print("graph yes")
64
        print("graph_category loadbalancer")
65
        print("graph_info Statistics from the Approx cache.")
66
        for filetype in get_file_types().keys():
67
            print("%s.label %s" % (filetype.lower(), filetype))
68
        exit()
69

    
70
for filetype, count in get_file_types().items():
71
    print("%s.value %d" % (filetype.lower(), count))
72

    
73
exit()