Projet

Général

Profil

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

root / plugins / mail / imapproxy_multi @ 59ecf3f1

Historique | Voir | Annoter | Télécharger (3,25 ko)

1 958f6a19 Niall Donegan
#!/usr/bin/env python
2
3
"""=cut
4
=head1 NAME 
5
6 e316273a Niall Donegan
 imapproxy  - Munin multigraph plugin to monitor imapproxy using pimpstat
7 958f6a19 Niall Donegan
8
=head1 CONFIGURATION
9
10
 This plugin should require no addition configuration.
11
12
=head1 MAGIC MARKERS
13
14
  #%# family=auto
15 e316273a Niall Donegan
  #%# capabilities=autoconf
16 958f6a19 Niall Donegan
17
=head1 Author
18
19
Niall Donegan <github@nialldonegan.me>
20
21
=head1 LICENSE
22
23
GPLv2
24
25
=cut"""
26
27
import sys
28
import os
29
import re
30
from subprocess import Popen,PIPE
31
32
33
def print_autoconf():
34
    which = Popen("which pimpstat", shell=True, stdout=PIPE)
35
    which.communicate()
36
    if not bool(which.returncode):
37
        print "yes"
38
    else:
39
        print "no (pimpstat not found)"
40
    sys.exit(0)
41
42
43 e316273a Niall Donegan
def print_config():
44
    print "multigraph imapproxy_cache"
45
    print "graph_title Cache Statistics For ImapProxy"
46
    print "graph_args -l 0 --base 1000"
47
    print "graph_total total"
48
    print "graph_vlabel Cache Connections / ${graph_period}"
49
    print "graph_category imapproxy"
50
    print "cache_hits.draw AREA"
51
    print "cache_hits.type DERIVE"
52
    print "cache_hits.label Cache Hits"
53
    print "cache_hits.min 0"
54
    print "cache_misses.draw STACK"
55
    print "cache_misses.type DERIVE"
56
    print "cache_misses.label Cache Misses"
57
    print "cache_misses.min 0"
58
    print 
59
    print "multigraph imapproxy_connections"
60
    print "graph_title Connection Statistics For ImapProxy"
61
    print "graph_args -l 0 --base 1000"
62
    print "graph_total total"
63
    print "graph_vlabel Connections / ${graph_period}"
64
    print "graph_category imapproxy"
65
    print "connections_reused.draw AREA"
66
    print "connections_reused.type DERIVE"
67
    print "connections_reused.label Reused Connections"
68
    print "connections_reused.min 0"
69
    print "connections_created.draw STACK"
70
    print "connections_created.type DERIVE"
71
    print "connections_created.label Created Connections"
72
    print "connections_created.min 0"
73 958f6a19 Niall Donegan
    sys.exit(0)
74
75
76 e316273a Niall Donegan
def print_fetch():
77
    cache_hits = 0
78
    cache_misses = 0
79
    connections_created = 0
80
    connections_reused = 0
81
    connections = Popen(
82
        "pimpstat -c | egrep '(Total (Reused|Created)|Cache (Hits|Misses))'", 
83
        shell=True,
84
        stdout=PIPE
85
    )
86
    for line in connections.stdout:
87
        if re.search(r'Hits', line):
88
            cache_hits = line.split()[0]
89
        if re.search(r'Misses', line):
90
            cache_misses = line.split()[0]
91
        if re.search(r'Created', line):
92
            connections_created = line.split()[0]
93
        if re.search(r'Reused', line):
94
            connections_reused = line.split()[0]
95
    print "multigraph imapproxy_cache"
96
    print "cache_hits.value %s" % cache_hits
97
    print "cache_misses.value %s" % cache_misses
98
    print
99
    print "multigraph imapproxy_connections"
100
    print "connections_created.value %s" % connections_created
101
    print "connections_reused.value %s" % connections_reused
102 958f6a19 Niall Donegan
103
    sys.exit(0)
104
105
def main():
106
    if len(sys.argv) > 1:
107
        command = sys.argv[1]
108
    else:
109
        command = "fetch"
110
111 e316273a Niall Donegan
    if command not in ["autoconf","config","fetch"]:
112 958f6a19 Niall Donegan
        print >> sys.stderr, "Command %s not known, please use either autoconf or suggest" % command
113
        sys.exit(1)
114
115
116
    if command == "autoconf":
117
        print_autoconf()
118
    elif command == "config":
119 e316273a Niall Donegan
        print_config()
120 958f6a19 Niall Donegan
    else:
121 e316273a Niall Donegan
        print_fetch()
122 958f6a19 Niall Donegan
123
124
if __name__ == '__main__':
125
    main()
126
127
# vim:syntax=python