HealthCheck::Diagnostic::RabbitMQ - Check connectivity and queues on a RabbitMQ server
version v1.3.1
Check that you can talk to the server.
my $health_check = HealthCheck->new( checks => [ HealthCheck::Diagnostic::RabbitMQ->new( rabbit_mq => \&connect_mq ), ] );
Or verify that a queue exists, has an appropriate number of listeners, and not too many queued messages waiting.
my $check_rabbit_mq => HealthCheck::Diagnostic::RabbitMQ->new( rabbit_mq => \&connect_mq, queue => $queue_name, channel => $channel, # default channel is 1 # All the rest are optional and only work on queue. listeners_min_critical => 0, listeners_min_warning => 1, listeners_max_critical => 3, listeners_max_warning => 3, # noop, matches critical messages_critical => 10_000, messages_warning => 1_000, ); my $health_check = HealthCheck->new( checks => [$check_rabbit_mq] );
Here the connect_mq function could be something like:
connect_mq
sub connect_mq { my $mq = Net::AMQP::RabbitMQ->new; $mq->connect( $host, { user => $username, password => $password, vhost => $vhost, } ); $mq->channel_open(1); return $mq; };
The $mq->channel_open is only needed to check a queue, in which case you will need to open the "channel" that will be used.
$mq->channel_open
Checking additional queues could be as easy as:
$health_check->register( { label => "other_rabbit_mq_check", invocant => $check_rabbit_mq, check => sub { shift->check( @_, queue => 'other.queue' }, } );
Determines if the RabbitMQ connection is available. Sets the status to "OK" or "CRITICAL" based on the return value from rabbit_mq->get_server_properties.
status
rabbit_mq->get_server_properties
If you pass in a "queue", it will instead check that the queue exists and if you additionally provide "listeners" or "messages" will also verify those limits. Limits are ignored without a queue.
Can be passed either to new or check.
new
check
A coderef that returns a Net::AMQP::RabbitMQ or Net::RabbitMQ or compatible object, or the object itself.
If using a coderef, the first returned value should always be the RabbitMQ object. If more than one value is returned, the second is assumed to be a Boolean "should_disconnect" flag (see below).
An optional Boolean value specifying whether to call ->disconnect on the RabbitMQ object after doing the health check. The default is false.
->disconnect
If specified as a parameter, it will override any value that might be returned by a "rabbit_mq" coderef as described above.
The name of the queue to check whether it exists.
Accomplishes the check by using rabbit_mq->queue_declare to try to declare a passive queue. Requires a "channel".
rabbit_mq->queue_declare
Allow specifying which channel will be used to check the "queue".
The passed in "rabbit_mq" must open this channel with channel_open to use this method.
channel_open
Defaults to 1.
With these set, checks to see that the number of listeners on the "queue" is within the exclusive range.
Checked in the order listed here:
Check is CRITICAL if the number of listeners is this many or less.
CRITICAL
Check is CRITICAL if the number of listeners is this many or more.
Check is WARNING if the number of listeners is this many or less.
WARNING
Check is WARNING if the number of listeners is this many or more.
Thresholds for number of messages in the queue.
Check is CRITICAL if the number of messages is this many or more.
Check is WARNING if the number of messages is this many or more.
Net::RabbitMQ does not support get_server_properties and so doesn't provide a way to just check that the server is responding to requests.
get_server_properties
HealthCheck::Diagnostic
None
Grant Street Group <developers@grantstreet.com>
This software is Copyright (c) 2018 - 2023 by Grant Street Group.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install HealthCheck::Diagnostic::RabbitMQ, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HealthCheck::Diagnostic::RabbitMQ
CPAN shell
perl -MCPAN -e shell install HealthCheck::Diagnostic::RabbitMQ
For more information on module installation, please visit the detailed CPAN module installation guide.