Created
July 27, 2012 10:24
-
-
Save jaylett/3187311 to your computer and use it in GitHub Desktop.
Django-celery plugin for munin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- python-mode -*- | |
import datetime | |
import sys | |
import os | |
import os.path | |
if os.path.isdir('/home/af-web/releases/current'): | |
# live | |
sys.path.append('/home/af-web/releases/current') | |
sys.path.append('/home/af-web/releases/current/bauhaus') | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'bauhaus.configs.live.settings' | |
from bauhaus.configs.live import settings | |
else: | |
# development | |
sys.path.append('/home/user/projects/world') | |
sys.path.append('/home/user/projects/world/bauhaus') | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'bauhaus.configs.development.settings' | |
from bauhaus.configs.development import settings | |
from django.core.management import setup_environ | |
setup_environ(settings) | |
# and we're going | |
from django.db.models import Sum | |
from djcelery.models import WorkerState, TaskState | |
from celery.states import ALL_STATES | |
if len(sys.argv) > 1 and sys.argv[1] == 'config': | |
# no workers because it's broken in the djcelery we use | |
# print """ | |
#multigraph celery_workers | |
#graph_title Celery workers | |
#graph_vlabel Number of workers | |
#graph_category Other | |
#alive.label Workers | |
#alive.type GAUGE | |
#""" | |
print """ | |
multigraph celery_runtime | |
graph_title Celery runtime | |
graph_vlabel Runtime seconds per second | |
graph_category Other | |
graph_args --base 1000 -l 0 | |
runtime.label Runtime | |
runtime.type GAUGE | |
multigraph celery_tasks | |
graph_title Celery tasks | |
graph_vlabel Tasks per second | |
graph_category Other | |
graph_args --base 1000 -l 0 | |
""" | |
for state in ALL_STATES: | |
print "%s.label %s" % (state, state) | |
print "%s.type GAUGE" % state | |
sys.exit(0) | |
# no workers because it's broken in the djcelery we use | |
#print "multigraph celery_workers\nalive.value %i\n" % ( | |
# len([w for w in WorkerState.objects.all() if w.is_alive()]) | |
# ) | |
SLICE = 30*60 # 30 minutes | |
cliff = datetime.datetime.now() - datetime.timedelta(seconds=SLICE) | |
print "multigraph celery_tasks" | |
for state in ALL_STATES: | |
print "%s.value %f" % ( | |
state, | |
TaskState.objects.filter( | |
state=state, | |
tstamp__gte=cliff | |
).count() / float(SLICE), | |
) | |
print "multigraph celery_runtime" | |
runtime = TaskState.objects.filter( | |
tstamp__gte=cliff, | |
).aggregate(Sum('runtime'))['runtime__sum'] / float(SLICE) | |
print "runtime.value %f" % runtime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment