[rabbitmq-discuss] Monitoring queue size via Nagios
Tim Rosenblatt
tim at cloudspace.com
Thu Oct 29 11:55:27 GMT 2009
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.
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.
#########
#!/usr/bin/ruby
VERSION_STRING = "Cloudspace RabbitMQ queue size checker v1.0 2009-10-20"
require 'optparse'
options = { :warning => 0, :critical => 0 }
OptionParser.new do |opts|
opts.banner = "Usage #{__FILE__} [options]"
opts.on("-?", "-h", "Help") do |v|
puts "use --help for usage information"
exit(3)
end
opts.on("--nagios", "Running from Nagios") do |v|
options[:nagios] = true
end
opts.on("-v", "--verbose", "Run verbosely") do |v|
options[:verbose] = v
end
opts.on("-V", "--version", "Prints \"#{VERSION_STRING}\"") do |v|
puts VERSION_STRING
exit(0)
end
opts.on("-w NUMBER", "--warning NUMBER", "Queue size for warning
threshold") do |n|
options[:warning] = n.to_i
puts "-w must be an integer greater than 0" or exit(3) unless
options[:warning] > 0
end
opts.on("-c NUMBER", "--critical NUMBER", "Queue size for critical
threshold") do |n|
options[:critical] = n.to_i
puts "-c must be an integer greater than 0" or exit(3) unless
options[:critical] > 0
end
end.parse!(ARGV)
output = `sudo rabbitmqctl list_queues`
queue_sizes = output.scan(/\d+/)
puts output.gsub(/\n/, "")
queue_sizes.each do |q_size|
q_size = q_size.to_i
exit(2) if q_size > options[:critical]
exit(1) if q_size > options[:warning]
end
exit(0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20091029/a51aaf52/attachment.htm
More information about the rabbitmq-discuss
mailing list