mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
45 lines
1.2 KiB
Python
Executable file
45 lines
1.2 KiB
Python
Executable file
#!/srv/newsblur/venv/newsblur/bin/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.get("REDIS_HOST", "localhost")
|
|
|
|
@property
|
|
def graph_config(self):
|
|
graph = {
|
|
'graph_category' : 'redis',
|
|
'graph_title' : 'Redis DB sizes',
|
|
'graph_args' : '-l 0',
|
|
}
|
|
|
|
stats = self.stats
|
|
graph.update(dict((("%s.label" % s, s) for s in stats.keys())))
|
|
graph.update(dict((("%s.draw" % s, 'LINE1') for s in stats.keys())))
|
|
|
|
return graph
|
|
|
|
def calculate_metrics(self):
|
|
return self.stats
|
|
|
|
@property
|
|
def stats(self):
|
|
r = redis.Redis(self.host)
|
|
info = r.info()
|
|
dbs = dict([(k, v) for k, v in info.items() if k.startswith('db')])
|
|
sizes = {}
|
|
for db, values in dbs.items():
|
|
for key, value in values.items():
|
|
if key == 'avg_ttl': continue
|
|
sizes[db+"_"+key] = value
|
|
return sizes
|
|
|
|
|
|
if __name__ == '__main__':
|
|
NBMuninGraph().run()
|
|
|
|
|