/celery_queue.py Secret
Last active
December 21, 2021 01:09
Star
You must be signed in to star a gist
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
''' | |
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]) |
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
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