NewsBlur/utils/munin/newsblur_updates.py

35 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2012-02-26 23:29:57 -08:00
import redis
from utils.munin.base import MuninGraph
graph_config = {
'graph_category' : 'NewsBlur',
'graph_title' : 'NewsBlur Updates',
'graph_vlabel' : '# of updates',
2011-03-24 13:01:56 -04:00
'update_queue.label': 'Queued Feeds last hour',
'feeds_fetched.label': 'Fetched feeds last hour',
'celery_update_feeds.label': 'Celery - Update Feeds',
'celery_new_feeds.label': 'Celery - New Feeds',
'celery_push_feeds.label': 'Celery - Push Feeds',
}
2010-09-08 10:52:04 -07:00
def calculate_metrics():
import datetime
from apps.rss_feeds.models import Feed
2012-02-26 23:29:57 -08:00
from django.conf import settings
hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
2012-02-26 23:29:57 -08:00
r = redis.Redis(connection_pool=settings.REDIS_POOL)
return {
'update_queue': Feed.objects.filter(queued_date__gte=hour_ago).count(),
2011-03-24 13:01:56 -04:00
'feeds_fetched': Feed.objects.filter(last_update__gte=hour_ago).count(),
2012-02-26 23:29:57 -08:00
'celery_update_feeds': r.llen("update_feeds"),
'celery_new_feeds': r.llen("new_feeds"),
'celery_push_feeds': r.llen("push_feeds"),
}
if __name__ == '__main__':
MuninGraph(graph_config, calculate_metrics).run()