myles / munin-plugins forked from jacobian/munin-plugins

Some munin plugins I wrote, and a little Python microframework for writing 'em.

This URL has Read+Write access

munin-plugins / perlbal_
100755 64 lines (52 sloc) 1.854 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
Munin script to monitor perlbal.
 
Following the munin style, this reads argv[0] to get the name of the pool
to monitor.
 
Currently reports raw requests/second, but would be cool to break it down
by response code/pool...
"""
 
import telnetlib
import socket
import munin
 
class Perlbal(munin.Plugin):
    
    env_vars = {
        "host": "localhost",
        "port": "60000"
    }
    
    def _connect(self):
        return telnetlib.Telnet(self.env["host"], int(self.env["port"]))
    
    def fetch(self, pool=None):
        if not pool: return []
        
        c = self._connect()
        c.write("show pool %s\r\n"% pool)
        data = c.read_until(".\r\n")
        nodelines = data.strip().split("\r\n")[:-1]
        nodes = (line.strip().split() for line in nodelines)
        return [("requests.value", sum(int(reqs) for node, reqs in nodes))]
    
    def config(self, pool=None):
        if not pool: return []
        return [
            ('graph_title', 'Perlbal requests in pool %s' % pool),
            ('graph_args', '-l 0 --base 1000'),
            ('graph_vlabel', 'Requests'),
            ('graph_category', 'Perlbal'),
            ('graph_info', 'Tracks the number of requests the %s pool handles' % pool),
            ('graph_period', 'second'),
            ('requests.label', 'Requests per second'),
            ('requests.type', 'DERIVE'),
            ('requests.min', '0'),
        ]
 
    def autoconf(self):
        try:
            self._connect()
        except socket.error:
            return False
        return True
    
    def suggest(self):
        c = self._connect()
        c.write("show pool\r\n")
        data = c.read_until(".\r\n").strip()
        return set(line.strip().split()[0] for line in data.split("\r\n") if line != '.')
    
if __name__ == '__main__':
    munin.run(Perlbal)