This commit is contained in:
Wraithan (Chris McDonald) 2012-07-02 15:22:25 -07:00
Родитель 1b842462e3
Коммит 71a92ad369
8 изменённых файлов: 0 добавлений и 127 удалений

Просмотреть файл

@ -1,31 +0,0 @@
import logging
import time
from django.core.management.base import BaseCommand
import redisutils
from graphite import graphite
from amo.tasks import task_stats
log = logging.getLogger('z.watch-celery')
class Command(BaseCommand):
help = "Subscribe to celery events and publish to graphite."
def handle(self, *args, **kw):
redis = redisutils.connections['master']
while 1:
try:
stats = []
d = zip(['pending', 'failed', 'total'], task_stats.stats())
for key, dict_ in d:
for name, value in dict_.items():
stats.append(('celery.tasks.%s.%s' % (key, name), value))
graphite.sendall(*stats)
except Exception, e:
log.error(e)
time.sleep(2)

Просмотреть файл

@ -4,12 +4,9 @@ import time
from django.conf import settings
import commonware.log
import celery.signals
import redisutils
import phpserialize
from celeryutils import task
from hera.contrib.django_utils import flush_urls
from django_statsd.clients import statsd
import amo
from abuse.models import AbuseReport
@ -129,57 +126,6 @@ def migrate_editor_eventlog(items, **kw):
log.warning("Couldn't find review for %d" % item.changed_id)
class TaskStats(object):
prefix = 'celery:tasks:stats'
pending = prefix + ':pending'
failed = prefix + ':failed'
run = prefix + ':run'
timer = prefix + ':timer'
@property
def redis(self):
# Keep this in a property so it's evaluated at runtime.
return redisutils.connections['master']
def on_sent(self, sender, **kw):
# sender is the name of the task (like "amo.tasks.ok").
# id in here.
self.redis.hincrby(self.pending, sender, 1)
self.redis.hset(self.timer, kw['id'], time.time())
def on_postrun(self, sender, **kw):
# sender is the task object. task_id in here.
pending = self.redis.hincrby(self.pending, sender.name, -1)
# Clamp pending at 0. Tasks could be coming in before we started
# tracking.
if pending < 0:
self.redis.hset(self.pending, sender.name, 0)
self.redis.hincrby(self.run, sender.name, 1)
start = self.redis.hget(self.timer, kw['task_id'])
if start:
t = (time.time() - float(start)) * 1000
statsd.timing('tasks.%s' % sender.name, int(t))
def on_failure(self, sender, **kw):
# sender is the task object.
self.redis.hincrby(self.failed, sender.name, 1)
def stats(self):
get = self.redis.hgetall
return get(self.pending), get(self.failed), get(self.run)
def clear(self):
for name in self.pending, self.failed, self.run, self.timer:
self.redis.delete(name)
task_stats = TaskStats()
celery.signals.task_sent.connect(task_stats.on_sent)
celery.signals.task_postrun.connect(task_stats.on_postrun)
celery.signals.task_failure.connect(task_stats.on_failure)
@task
def find_abuse_escalations(addon_id, **kw):
amo.set_user(get_task_user())

Просмотреть файл

@ -57,7 +57,6 @@ urlpatterns = patterns('',
url('^elastic$', views.elastic, name='zadmin.elastic'),
url('^mail$', views.mail, name='zadmin.mail'),
url('^email-devs$', views.email_devs, name='zadmin.email_devs'),
url('^celery$', views.celery, name='zadmin.celery'),
url('^addon-name-blocklist$', views.addon_name_blocklist,
name='zadmin.addon-name-blocklist'),
url('^addon-search$', views.addon_search, name='zadmin.addon-search'),

Просмотреть файл

@ -33,7 +33,6 @@ from amo import messages, get_user
from amo.decorators import (any_permission_required, json_view, login_required,
post_required)
from amo.mail import FakeEmailBackend
from amo.tasks import task_stats
from amo.urlresolvers import reverse
from amo.utils import chunked, sorted_groupby
from bandwagon.cron import reindex_collections
@ -642,18 +641,6 @@ def email_devs(request):
dict(form=form, preview_csv=preview_csv))
@admin.site.admin_view
def celery(request):
if request.method == 'POST' and 'reset' in request.POST:
task_stats.clear()
return redirect('zadmin.celery')
pending, failures, totals = task_stats.stats()
ctx = dict(pending=pending, failures=failures, totals=totals,
now=datetime.now())
return jingo.render(request, 'zadmin/celery.html', ctx)
@admin.site.admin_view
def addon_name_blocklist(request):
rn = ReverseNameLookup()

Просмотреть файл

@ -36,7 +36,6 @@ def admin_site_links():
'tools': [
('View request environment', url('amo.env')),
('Manage elasticsearch', url('zadmin.elastic')),
('View celery stats', url('zadmin.celery')),
('Purge data from memcache', url('zadmin.memcache')),
('Purge pages from zeus', url('zadmin.hera')),
('View graphite trends', url('amo.graphite', 'addons')),

Просмотреть файл

@ -219,7 +219,6 @@ def admin_site_links():
('View request environment', reverse('amo.env')),
('Manage elasticsearch', reverse('zadmin.elastic')),
('Manage EcoSystem', reverse('mkt.zadmin.ecosystem')),
('View celery stats', reverse('zadmin.celery')),
('Purge data from memcache', reverse('zadmin.memcache')),
('Purge pages from zeus', reverse('zadmin.hera')),
('View graphite trends', reverse('amo.graphite', args=['addons'])),

Просмотреть файл

@ -1,13 +0,0 @@
[program:celery-preview]
command=/usr/bin/python2.6 /data/amo_python/www/preview/zamboni/manage.py watch_celery
directory=/data/amo_python/www/preview/zamboni
user=apache
numprocs=1
; stdout_logfile=/var/log/celeryd-prod-supervisor.log
; stderr_logfile=/var/log/celeryd-prod-supervisor.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 10

Просмотреть файл

@ -1,13 +0,0 @@
[program:celery-prod]
command=/usr/bin/python2.6 /data/amo_python/www/prod/zamboni/manage.py watch_celery
directory=/data/amo_python/www/prod/zamboni
user=apache
numprocs=1
; stdout_logfile=/var/log/celeryd-prod-supervisor.log
; stderr_logfile=/var/log/celeryd-prod-supervisor.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 10