How to use RabbitMQ http api to see what queue had a messages in a ready state

10.3k views Asked by At

I have a RabbitMQ server setup with thousands of queues. Of which only about 5 of these are persistent queues. Every now and then there is a back up of a queue that will have about 5-10 messages in a ready state. These messages do not appear to be in the persistent queues. I want to find out which queues had the messages in a ready state, but the only indication that it is happening is on the overview page of the web management console which is for all queues. enter image description here

Is there a way to query Rabbit to tell me the stat info for messages that were in a ready state for a period of minutes and which queue they were in?

2

There are 2 answers

0
Balint Pato On

I would use the HTTP API.

http://rabbit-broker:15672/api/queues

This will give you a list of the current queue states in JSON so you'll have to keep polling it. Store the "messages_ready" for given queue "name" for the period you want to monitor. Now you'll be able to see which queues have that backlog spike.

You can use simple curl as well as whichever platform you prefer with an HTTP client.

Please note: the user you'll connect will have to have monitor tag to access all the queue information.

Out of the box there is no easy way AFAIK, you'd have to manually click through the queues and look at their graphs in the UI for the last hour, which is tedious.

0
tporeba On

I had similar requirements and I found a better way than polling. The docs say that you may get raw samples via api if you use special parameters in the request.

For example in your case, if you are interested in messages with ready state, you may ask your queue for a history of queue lengths, for example last 60 seconds with samples every 1 second (note 15672 is the default port used by rabbitmq_management):

http://rabbitHost:15672/api/queues/vhost/queue?lengths_age=60&lengths_incr=1

For default vhost=/ it will be:

http://rabbitHost:15672/api/queues/%2F/queue?lengths_age=60&lengths_incr=1

Then in the result json there will be some additional _details objects like this:

"messages_ready_details": {
    "avg": 8.524590163934427,
    "avg_rate": 0.08333333333333333,
    "samples": [{
            "timestamp": 1532699694000,
            "sample": 5
        }, {
            "timestamp": 1532699693000,
            "sample": 11
        }, 
        <... more samples ...>
    ],
    "rate": -6.0
},
"messages_ready": 5,

Then on this raw data you may do any stats you need. Other raw data samples appear if you use differen parameters in

What sampling will appear?                                               What parameters are required for it to appear?
Messages sent and received                                              msg_rates_age / msg_rates_incr
Bytes sent and received                                                     data_rates_age / data_rates_incr
Queue lengths                                                                     lengths_age / lengths_incr
Node statistics (e.g. file descriptors, disk space free)        node_stats_age / node_stats_incr