[rabbitmq-discuss] Low impact statistics gathering for queues

Emile Joubert emile at rabbitmq.com
Mon Mar 11 10:43:30 GMT 2013


Hi,

On 09/03/13 14:46, sapelzin at icontrol.com wrote:
> Our application can utilize a lot of queues, as many as 100k.  We would
> like to regularly query a queue count, and message counts for specific
> queues.  The overhead for calling rabbitmqctl -list_queues with a large
> number of queues is too high.  Is there an alternative for just querying
> the stats we need?

You can get a quick queue count with this command:

rabbitmqctl eval 'mnesia:table_info(rabbit_queue, size).'

rabbitmqctl is not the best way of getting the message count for just a
few queues if there are many queues, because it will query all queues.
If the queue permissions and parameters allow it then it may be possible
to get this information by using an AMQP library and the passive queue
declare method, which reports message count:

http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.declare-ok

The management plugin can also be used to obtain this information using
the HTTP API. For details see http://www.rabbitmq.com/management.html
and the HTTP API documentation linked from there.


It is possible to use a complicated rabbitmqctl eval parameter to return
the number of messages in a particular queue (queue_name in this
example), but this is a fragile option that is may stop working when you
upgrade:

rabbitmqctl eval '{ok, [{messages, Count}]} =
rabbit_amqqueue:with(rabbit_misc:r(<<"/">>, queue, <<"queue_name">>),
fun(Q) ->  gen_server2:call(element(7, Q), {info, [messages]}) end), Count.'





-Emile







More information about the rabbitmq-discuss mailing list