Retrieve queue length with Celery (RabbitMQ, Django)

为君一笑 提交于 2019-12-08 15:55:42

问题


I'm using Celery in a django project, my broker is RabbitMQ, and I want to retrieve the length of the queues. I went through the code of Celery but did not find the tool to do that. I found this issue on stackoverflow (Check RabbitMQ queue size from client), but I don't find it satisfying.

Everything is setup in celery, so there should be some kind of magic method to retrieve what I want, without specifying a channel / connection.

Does anyone have any idea about this question ?

Thanks !


回答1:


Here is an example on how to read the queue length in rabbitMQ for a given queue:

def get_rabbitmq_queue_length(q):
    from pyrabbit.api import Client
    from pyrabbit.http import HTTPError

    count = 0

    try:
        cl = Client('localhost:15672', 'guest', 'guest')
        if cl.is_alive():
            count = cl.get_queue_depth('/', q)
    except HTTPError as e:
        print "Exception: Could not establish to rabbitmq http api: " + str(e) + " Check for port, proxy, username/pass configuration errors"
        raise

    return count

This is using pyrabbit as previously suggested by Philip




回答2:


PyRabbit is probably what you are looking for, it is a Python interface to the RabbitMQ management interface API. It will allow you to query for queues and their current message counts.




回答3:


You can inspect the workers in celery by using inspect module. Here is the guide.

Also for RabbitMQ there are some command line command.



来源:https://stackoverflow.com/questions/17863626/retrieve-queue-length-with-celery-rabbitmq-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!