2013-03-18 15:18:43 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from utils.munin.base import MuninGraph
|
|
|
|
import os, redis
|
|
|
|
|
|
|
|
class NBMuninGraph(MuninGraph):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(NBMuninGraph, self).__init__(*args, **kwargs)
|
|
|
|
self.host = os.environ["REDIS_HOST"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def graph_config(self):
|
|
|
|
graph = {
|
|
|
|
'graph_category' : 'redis',
|
|
|
|
'graph_title' : 'Redis DB sizes',
|
|
|
|
'graph_args' : '-l 0',
|
|
|
|
}
|
|
|
|
|
|
|
|
stats = self.stats
|
2013-03-28 17:29:27 -07:00
|
|
|
graph.update(dict((("%s.label" % s, s) for s in stats.keys())))
|
|
|
|
graph.update(dict((("%s.draw" % s, 'LINE1') for s in stats.keys())))
|
2013-03-18 15:18:43 -07:00
|
|
|
|
|
|
|
return graph
|
|
|
|
|
|
|
|
def calculate_metrics(self):
|
|
|
|
return self.stats
|
|
|
|
|
|
|
|
@property
|
|
|
|
def stats(self):
|
|
|
|
r = redis.Redis(self.host)
|
|
|
|
info = r.info()
|
2015-02-11 15:17:55 -08:00
|
|
|
dbs = dict([(k, v) for k, v in info.items() if k.startswith('db')])
|
2013-03-18 15:18:43 -07:00
|
|
|
sizes = {}
|
|
|
|
for db, values in dbs.items():
|
|
|
|
for key, value in values.items():
|
2015-02-11 15:18:24 -08:00
|
|
|
if key == 'avg_ttl': continue
|
2013-03-18 15:18:43 -07:00
|
|
|
sizes[db+"_"+key] = value
|
|
|
|
return sizes
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NBMuninGraph().run()
|
|
|
|
|
|
|
|
|