2010-09-23 10:29:18 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from utils.munin.base import MuninGraph
|
|
|
|
|
|
|
|
graph_config = {
|
|
|
|
'graph_category' : 'NewsBlur',
|
|
|
|
'graph_title' : 'NewsBlur Loadtimes',
|
|
|
|
'graph_vlabel' : 'Loadtimes (seconds)',
|
|
|
|
'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)',
|
2010-09-29 13:07:07 -04:00
|
|
|
'feeds_loaded_hour.label': 'Feeds Loaded (Hour)',
|
2010-09-23 10:29:18 -04:00
|
|
|
}
|
|
|
|
|
2011-03-23 15:43:15 -04:00
|
|
|
def calculate_metrics():
|
|
|
|
from django.db.models import Avg, Min, Max, Count
|
|
|
|
import datetime
|
|
|
|
from apps.rss_feeds.models import FeedLoadtime
|
|
|
|
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=60)
|
2010-09-23 10:29:18 -04:00
|
|
|
|
2011-03-23 15:43:15 -04:00
|
|
|
averages = dict(avg=Avg('loadtime'), max=Max('loadtime'), min=Min('loadtime'), count=Count('loadtime'))
|
|
|
|
hour = FeedLoadtime.objects.filter(date_accessed__gte=hour_ago).aggregate(**averages)
|
|
|
|
return {
|
|
|
|
'feed_loadtimes_avg_hour': hour['avg'],
|
|
|
|
'feed_loadtimes_min_hour': hour['min'],
|
|
|
|
'feed_loadtimes_max_hour': hour['max'],
|
|
|
|
'feeds_loaded_hour': hour['count'],
|
|
|
|
}
|
2010-09-23 10:29:18 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-03-23 15:43:15 -04:00
|
|
|
MuninGraph(graph_config, calculate_metrics).run()
|