2010-09-23 10:29:18 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from utils.munin.base import MuninGraph
|
2012-09-27 15:21:38 -07:00
|
|
|
from django.conf import settings
|
|
|
|
import datetime
|
2010-09-23 10:29:18 -04:00
|
|
|
|
2012-09-27 10:45:40 -07:00
|
|
|
class NBMuninGraph(MuninGraph):
|
2010-09-23 10:29:18 -04:00
|
|
|
|
2012-09-27 10:45:40 -07:00
|
|
|
@property
|
|
|
|
def graph_config(self):
|
|
|
|
return {
|
|
|
|
'graph_category' : 'NewsBlur',
|
|
|
|
'graph_title' : 'NewsBlur Loadtimes',
|
|
|
|
'graph_vlabel' : 'Loadtimes (seconds)',
|
2012-09-28 09:50:12 -07:00
|
|
|
'graph_args' : '-l 0',
|
2012-09-27 10:45:40 -07:00
|
|
|
'feed_loadtimes_avg_hour.label': 'Feed Loadtimes Avg (Hour)',
|
|
|
|
'feed_loadtimes_min_hour.label': 'Feed Loadtimes Min (Hour)',
|
|
|
|
'feed_loadtimes_max_hour.label': 'Feed Loadtimes Max (Hour)',
|
|
|
|
'feeds_loaded_hour.label': 'Feeds Loaded (Hour)',
|
|
|
|
}
|
|
|
|
|
|
|
|
def calculate_metrics(self):
|
|
|
|
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=60)
|
2012-09-27 15:21:38 -07:00
|
|
|
times = settings.MONGOANALYTICSDB.nbanalytics.page_loads.aggregate([{
|
|
|
|
"$match": {
|
|
|
|
"date": {
|
|
|
|
"$gte": hour_ago,
|
|
|
|
},
|
|
|
|
"path": {
|
|
|
|
"$in": [
|
|
|
|
"/reader/feed/",
|
|
|
|
"/social/stories/",
|
|
|
|
"/reader/river_stories/",
|
|
|
|
"/social/river_stories/",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
"$group": {
|
|
|
|
"_id" : 1,
|
|
|
|
"count" : {"$sum": 1},
|
|
|
|
"avg" : {"$avg": "$duration"},
|
|
|
|
"min" : {"$min": "$duration"},
|
|
|
|
"max" : {"$max": "$duration"},
|
|
|
|
},
|
|
|
|
}])
|
|
|
|
|
|
|
|
load_avg = 0
|
|
|
|
load_min = 0
|
|
|
|
load_max = 0
|
|
|
|
load_count = 0
|
|
|
|
if times['result']:
|
|
|
|
load_avg = times['result'][0]['avg']
|
|
|
|
load_min = times['result'][0]['min']
|
|
|
|
load_max = times['result'][0]['max']
|
|
|
|
load_count = times['result'][0]['count']
|
|
|
|
|
2012-09-27 10:45:40 -07:00
|
|
|
return {
|
2012-09-27 15:21:38 -07:00
|
|
|
'feed_loadtimes_avg_hour': load_avg,
|
|
|
|
'feed_loadtimes_min_hour': load_min,
|
|
|
|
'feed_loadtimes_max_hour': load_max,
|
|
|
|
'feeds_loaded_hour': load_count,
|
2012-09-27 10:45:40 -07:00
|
|
|
}
|
2010-09-23 10:29:18 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-09-27 10:45:40 -07:00
|
|
|
NBMuninGraph().run()
|