Skip to content

Instantly share code, notes, and snippets.

@conorbranagan

conorbranagan/celery_queue.py Secret

Last active Feb 4, 2019
Embed
What would you like to do?
'''
Fetches the Celery queue length
'''
from checks import AgentCheck
class CeleryQueue(AgentCheck):
def check(self, instance):
try:
import redis
except ImportError:
raise Exception('Python Redis Module can not be imported. Please check the installation instruction on the Datadog Website')
keys = instance.get('queue_keys', [])
if not keys:
raise Exception('No queue keys were found in the yaml configuration file')
list_params = ['host', 'port', 'db', 'password']
connection_params = dict((k, instance[k]) for k in list_params if k in instance)
db = redis.Redis(**connection_params)
for key in keys:
self.gauge("celery.queue.length", db.llen(key), tags=["queue:%s" % key])
init_config:
instances:
- host: localhost
port: 6379
db: 14
# password: mypassword
queue_keys: # A list of keys associated with the Celery queues
- key1
- key2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment