I was searching for a Nagios plugin to monitor RabbitMQ, and only found an unanswered question to this mailing list of how it could be done.<br><br>I wanted to share the Ruby code I wrote for monitoring queue size. A next step for monitoring is to connect directly to the queue with the Bunny gem and make sure it is accepting connections.<br>
<br>#########<br><br>#!/usr/bin/ruby<br><br>VERSION_STRING = "Cloudspace RabbitMQ queue size checker v1.0 2009-10-20"<br><br><br>require 'optparse'<br><br>options = { :warning => 0, :critical => 0 }<br>
<br>OptionParser.new do |opts|<br> opts.banner = "Usage #{__FILE__} [options]"<br><br> opts.on("-?", "-h", "Help") do |v|<br> puts "use --help for usage information"<br>
exit(3)<br> end<br><br> opts.on("--nagios", "Running from Nagios") do |v|<br> options[:nagios] = true<br> end<br><br> opts.on("-v", "--verbose", "Run verbosely") do |v|<br>
options[:verbose] = v<br> end<br><br> opts.on("-V", "--version", "Prints \"#{VERSION_STRING}\"") do |v|<br> puts VERSION_STRING<br> exit(0)<br> end<br><br> opts.on("-w NUMBER", "--warning NUMBER", "Queue size for warning threshold") do |n|<br>
options[:warning] = n.to_i<br> puts "-w must be an integer greater than 0" or exit(3) unless options[:warning] > 0<br> end<br><br> opts.on("-c NUMBER", "--critical NUMBER", "Queue size for critical threshold") do |n|<br>
options[:critical] = n.to_i<br> puts "-c must be an integer greater than 0" or exit(3) unless options[:critical] > 0<br> end<br><br>end.parse!(ARGV)<br><br><br>output = `sudo rabbitmqctl list_queues`<br>
queue_sizes = output.scan(/\d+/)<br><br>puts output.gsub(/\n/, "")<br><br>queue_sizes.each do |q_size|<br> q_size = q_size.to_i<br> exit(2) if q_size > options[:critical]<br> exit(1) if q_size > options[:warning]<br>
end<br><br>exit(0)<br><br>