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 = &quot;Cloudspace RabbitMQ queue size checker v1.0 2009-10-20&quot;<br><br><br>require &#39;optparse&#39;<br><br>options = { :warning =&gt; 0, :critical =&gt; 0 }<br>

<br>OptionParser.new do |opts|<br>� opts.banner = &quot;Usage #{__FILE__} [options]&quot;<br><br>� opts.on(&quot;-?&quot;, &quot;-h&quot;, &quot;Help&quot;) do |v|<br>��� puts &quot;use --help for usage information&quot;<br>

��� exit(3)<br>� end<br><br>� opts.on(&quot;--nagios&quot;, &quot;Running from Nagios&quot;) do |v|<br>��� options[:nagios] = true<br>� end<br><br>� opts.on(&quot;-v&quot;, &quot;--verbose&quot;, &quot;Run verbosely&quot;) do |v|<br>

��� options[:verbose] = v<br>� end<br><br>� opts.on(&quot;-V&quot;, &quot;--version&quot;, &quot;Prints \&quot;#{VERSION_STRING}\&quot;&quot;) do |v|<br>��� puts VERSION_STRING<br>��� exit(0)<br>� end<br><br>� opts.on(&quot;-w NUMBER&quot;, &quot;--warning NUMBER&quot;, &quot;Queue size for warning threshold&quot;) do |n|<br>

��� options[:warning] = n.to_i<br>��� puts &quot;-w must be an integer greater than 0&quot; or exit(3) unless options[:warning] &gt; 0<br>� end<br><br>� opts.on(&quot;-c NUMBER&quot;, &quot;--critical NUMBER&quot;, &quot;Queue size for critical threshold&quot;) do |n|<br>

��� options[:critical] = n.to_i<br>��� puts &quot;-c must be an integer greater than 0&quot; or exit(3) unless options[:critical] &gt; 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/, &quot;&quot;)<br><br>queue_sizes.each do |q_size|<br>� q_size = q_size.to_i<br>� exit(2) if q_size &gt; options[:critical]<br>� exit(1) if q_size &gt; options[:warning]<br>

end<br><br>exit(0)<br><br>