2012-09-27 12:12:22 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from utils.munin.base import MuninGraph
|
|
|
|
|
|
|
|
class NBMuninGraph(MuninGraph):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def graph_config(self):
|
|
|
|
graph = {
|
|
|
|
'graph_category' : 'NewsBlur',
|
|
|
|
'graph_title' : 'NewsBlur Task Codes',
|
|
|
|
'graph_vlabel' : 'Status codes on feed fetch',
|
|
|
|
}
|
2012-09-27 16:51:52 -07:00
|
|
|
stats = self.stats
|
|
|
|
graph.update(dict((("_%s.label" % s['_id'], s['_id']) for s in stats)))
|
|
|
|
graph['graph_order'] = ' '.join(sorted(("_%s" % s['_id']) for s in stats))
|
|
|
|
|
2012-09-27 12:12:22 -07:00
|
|
|
return graph
|
|
|
|
|
|
|
|
def calculate_metrics(self):
|
2012-09-27 13:18:51 -07:00
|
|
|
servers = dict((("_%s" % s['_id'], s['feeds']) for s in self.stats))
|
2012-09-27 16:51:52 -07:00
|
|
|
|
2012-09-27 12:12:22 -07:00
|
|
|
return servers
|
|
|
|
|
|
|
|
@property
|
|
|
|
def stats(self):
|
|
|
|
import datetime
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
stats = settings.MONGOANALYTICSDB.nbanalytics.feed_fetches.aggregate([{
|
|
|
|
"$match": {
|
|
|
|
"date": {
|
|
|
|
"$gt": datetime.datetime.now() - datetime.timedelta(minutes=5),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
"$group": {
|
|
|
|
"_id" : "$feed_code",
|
|
|
|
"feeds" : {"$sum": 1},
|
|
|
|
},
|
|
|
|
}])
|
|
|
|
|
|
|
|
return stats['result']
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NBMuninGraph().run()
|