mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
The current implementation only works if redis is used as broker. Otherwise it would throw an Exception, which causes a 500 to be returend. Now we just don't have celery metrics in those cases. Fixes #2029
This commit is contained in:
@@ -286,17 +286,19 @@ def metric_values():
|
|||||||
metrics['pretix_model_instances']['{model="%s"}' % m._meta] = estimate_count_fast(m)
|
metrics['pretix_model_instances']['{model="%s"}' % m._meta] = estimate_count_fast(m)
|
||||||
|
|
||||||
if settings.HAS_CELERY:
|
if settings.HAS_CELERY:
|
||||||
client = app.broker_connection().channel().client
|
channel = app.broker_connection().channel()
|
||||||
for q in settings.CELERY_TASK_QUEUES:
|
if hasattr(channel, 'client') and channel.client is not None:
|
||||||
llen = client.llen(q.name)
|
client = channel.client
|
||||||
lfirst = client.lindex(q.name, -1)
|
for q in settings.CELERY_TASK_QUEUES:
|
||||||
metrics['pretix_celery_tasks_queued_count']['{queue="%s"}' % q.name] = llen
|
llen = client.llen(q.name)
|
||||||
if lfirst:
|
lfirst = client.lindex(q.name, -1)
|
||||||
ldata = json.loads(lfirst)
|
metrics['pretix_celery_tasks_queued_count']['{queue="%s"}' % q.name] = llen
|
||||||
dt = time.time() - ldata.get('created', 0)
|
if lfirst:
|
||||||
metrics['pretix_celery_tasks_queued_age_seconds']['{queue="%s"}' % q.name] = dt
|
ldata = json.loads(lfirst)
|
||||||
else:
|
dt = time.time() - ldata.get('created', 0)
|
||||||
metrics['pretix_celery_tasks_queued_age_seconds']['{queue="%s"}' % q.name] = 0
|
metrics['pretix_celery_tasks_queued_age_seconds']['{queue="%s"}' % q.name] = dt
|
||||||
|
else:
|
||||||
|
metrics['pretix_celery_tasks_queued_age_seconds']['{queue="%s"}' % q.name] = 0
|
||||||
|
|
||||||
return metrics
|
return metrics
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user