mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
67 lines
1.9 KiB
Python
Executable file
67 lines
1.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
from utils.munin.base import MuninGraph
|
|
import datetime
|
|
from django.conf import settings
|
|
|
|
|
|
class NBMuninGraph(MuninGraph):
|
|
|
|
@property
|
|
def graph_config(self):
|
|
graph = {
|
|
'graph_category' : 'NewsBlur',
|
|
'graph_title' : 'NewsBlur Task Server Fetches',
|
|
'graph_vlabel' : '# of fetches / server',
|
|
'total.label': 'total',
|
|
}
|
|
stats = self.stats
|
|
graph.update(dict((("%s.label" % s['_id'], s['_id']) for s in stats)))
|
|
graph.update(dict((("%s.draw" % s['_id'], "LINESTACK") for s in stats)))
|
|
graph['graph_order'] = ' '.join(sorted(s['_id'] for s in stats))
|
|
return graph
|
|
|
|
def calculate_metrics(self):
|
|
servers = dict((("%s" % s['_id'], s['feeds']) for s in self.stats))
|
|
servers['total'] = self.total[0]['feeds']
|
|
return servers
|
|
|
|
@property
|
|
def stats(self):
|
|
stats = settings.MONGOANALYTICSDB.nbanalytics.feed_fetches.aggregate([{
|
|
"$match": {
|
|
"date": {
|
|
"$gte": datetime.datetime.now() - datetime.timedelta(minutes=5),
|
|
},
|
|
},
|
|
}, {
|
|
"$group": {
|
|
"_id" : "$server",
|
|
"feeds" : {"$sum": 1},
|
|
},
|
|
}])
|
|
|
|
return stats['result']
|
|
|
|
@property
|
|
def total(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" : 1,
|
|
"feeds" : {"$sum": 1},
|
|
},
|
|
}])
|
|
|
|
return stats['result']
|
|
|
|
|
|
if __name__ == '__main__':
|
|
NBMuninGraph().run()
|