-
Notifications
You must be signed in to change notification settings - Fork 995
/
newsblur_tasks_servers.py
executable file
·69 lines (58 loc) · 1.98 KB
/
newsblur_tasks_servers.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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',
'graph_args' : '-l 0',
'total.label' : 'total',
'total.draw' : 'LINE1',
}
stats = self.stats
graph.update(dict((("%s.label" % s['_id'], s['_id']) for s in stats)))
graph.update(dict((("%s.draw" % s['_id'], "AREASTACK") 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()