jacobian / munin-plugins

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

This URL has Read+Write access

jacobian (author)
Thu Feb 26 19:59:40 -0800 2009
commit  e3a20e9e26ecc4dc341d5d9bbdd095fd7f9e1c1d
tree    089caa66933d93a949c86d6f7cf367d7154be55f
parent  511b7632c54659e8da97640ce2c940655d6ebfde
munin-plugins / trac_milestones
100755 40 lines (30 sloc) 1.312 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
#!/usr/bin/python
 
import munin
from trac_tickets import TracTickets
 
class TracMilestone(TracTickets):
        
    def config(self):
        env = self._connect()
        
        yield ('graph_title', 'Trac milestones')
        yield ('graph_args', '-l 0 --base 1000')
        yield ('graph_vlabel', 'Open tickets')
        yield ('graph_scale', 'no')
        yield ('graph_category', 'Trac')
        yield ('graph_info', 'Progress towards future Trac milestones')
        for m in self.get_milestones(env):
            label = m.name.replace(' ', '_').replace('.', '_')
            yield ("%s.label" % label, label)
            yield ("%s.info" % label, m.name)
    
    def fetch(self):
        from trac.ticket.query import Query
        
        env = self._connect()
        cursor = env.get_db_cnx().cursor()
        
        for m in self.get_milestones(env):
            label = m.name.replace(' ', '_').replace('.', '_')
            q = Query.from_string(env, "status=new|assigned|reopened&milestone=%s" % m.name)
            cursor.execute(*q.get_sql())
            yield ("%s.value" % label, len(list(cursor)))
        
    def get_milestones(self, env):
        from trac.ticket import Milestone
        return Milestone.select(env, False)
 
if __name__ == '__main__':
    munin.run(TracMilestone)