Skip to content

Instantly share code, notes, and snippets.

@conorbranagan
Last active December 21, 2021 01:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save conorbranagan/87307c4376f64895f54c to your computer and use it in GitHub Desktop.
Save conorbranagan/87307c4376f64895f54c to your computer and use it in GitHub Desktop.
'''
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