2020-12-03 14:05:32 -05:00
|
|
|
#!/srv/newsblur/venv/newsblur3/bin/python
|
2012-09-27 10:45:40 -07:00
|
|
|
from utils.munin.base import MuninGraph
|
2020-12-10 12:40:12 -05:00
|
|
|
import os
|
2021-01-19 09:40:13 -05:00
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "newsblur_web.settings"
|
2020-12-10 12:42:12 -05:00
|
|
|
import django
|
|
|
|
django.setup()
|
2012-09-27 10:45:40 -07:00
|
|
|
|
|
|
|
class NBMuninGraph(MuninGraph):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def graph_config(self):
|
|
|
|
graph = {
|
|
|
|
'graph_category' : 'NewsBlur',
|
2012-09-27 10:47:49 -07:00
|
|
|
'graph_title' : 'NewsBlur Task Pipeline',
|
2012-09-27 10:45:40 -07:00
|
|
|
'graph_vlabel' : 'Feed fetch pipeline times',
|
2012-09-28 09:50:12 -07:00
|
|
|
'graph_args' : '-l 0',
|
2012-09-27 10:45:40 -07:00
|
|
|
'feed_fetch.label': 'feed_fetch',
|
|
|
|
'feed_process.label': 'feed_process',
|
|
|
|
'page.label': 'page',
|
|
|
|
'icon.label': 'icon',
|
|
|
|
'total.label': 'total',
|
|
|
|
}
|
|
|
|
return graph
|
|
|
|
|
|
|
|
def calculate_metrics(self):
|
|
|
|
return self.stats
|
|
|
|
|
|
|
|
@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": 1,
|
|
|
|
"feed_fetch": {"$avg": "$feed_fetch"},
|
|
|
|
"feed_process": {"$avg": "$feed_process"},
|
|
|
|
"page": {"$avg": "$page"},
|
|
|
|
"icon": {"$avg": "$icon"},
|
|
|
|
"total": {"$avg": "$total"},
|
|
|
|
},
|
|
|
|
}])
|
|
|
|
|
2016-11-20 13:11:56 -08:00
|
|
|
return list(stats)[0]
|
2012-09-27 10:45:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
NBMuninGraph().run()
|