<?xml version="1.0" encoding="UTF-8"?>
<plugin-url>
  <approved type="boolean">true</approved>
  <author>Mike Mangino</author>
  <cached-tag-list>starling</cached-tag-list>
  <canonical-name nil="true"></canonical-name>
  <code>class MissingLibrary &lt; StandardError; end
class StarlingMonitor &lt; Scout::Plugin

  
  attr_accessor :connection
  
  
  def setup_starling
    begin
      require 'starling'
    rescue LoadError
      begin
        require &quot;rubygems&quot;
        require 'starling'
      rescue LoadError
        raise MissingLibrary
      end
    end
    self.connection=Starling.new(&quot;#{option(:host)}:#{option(:port)}&quot;)
    @report = {}
  end
  
    
  
  def build_report
    begin
      setup_starling
      connection.sizeof(:all).each do |queue_name,item_count|
        check_queue(queue_name,item_count) if should_check_queue?(queue_name)
      end
      report(@report)
    rescue  MissingLibrary=&gt;e
      error(&quot;Could not load all required libraries&quot;,
            &quot;I failed to load the starling library. Please make sure it is installed.&quot;)
    rescue Exception=&gt;e
      error(&quot;Got unexpected error: #{e} #{e.class}&quot;)
    end
  end

  def should_check_queue?(name)
    option(:queue_re).nil? or /#{option(:queue_re)}/ =~ name
  end
  
  def check_queue(name,depth)
    q_depth = (depth||0).to_i
    @report ||= {}
    @report[name] = q_depth
    if q_depth &gt; option(:max_depth).to_i
      alert(&quot;Max Queue Depth for #{name} exceeded&quot;,&quot;#{q_depth} items is more than the max allowed #{option(:max_depth)}&quot;)
    end
  end

end</code>
  <created-at type="datetime">2008-08-08T09:42:03-07:00</created-at>
  <default-triggers type="yaml" nil="true"></default-triggers>
  <description>Monitors the number of items in a starling queue, generating an alert if the maximum queue depth is exceeded for a given queue. </description>
  <featured type="boolean">false</featured>
  <id type="integer">52</id>
  <metadata type="yaml">--- |
options:
  host:
    name: Host
    notes: The host to monitor
    default: 127.0.0.1
  port:
    name: Port
    notes: The port starling is running on
    default: 61613
  queue_re:
    name: Name Reqular Expresssion
    notes: Pattern to test against queue names to select queues to monitor 
    default: 
  max_depth: 
    name: Maximum Items
    notes: Alert if the queue contains more items than this
    default: 4000
  

</metadata>
  <name>Starling Monitor</name>
  <plugins-count type="integer">10</plugins-count>
  <rating-avg type="decimal">0.0</rating-avg>
  <rating-count type="integer">0</rating-count>
  <rating-total type="integer">0</rating-total>
  <readme>Monitor the number of items in a starling queue</readme>
  <schema type="yaml" nil="true"></schema>
  <scout-version type="integer">2</scout-version>
  <short-description>Monitors the number of items in a starling queue, generating an alert if the maximum queue depth is exceeded for a given queue. </short-description>
  <tested-platforms>linux</tested-platforms>
  <total-usage-count type="integer">0</total-usage-count>
  <updated-at type="datetime">2009-09-23T23:03:25-07:00</updated-at>
  <url>http://github.com/itsderek23/er-scout-plugins/raw/57d26e85056c6f22e6b72d37b18f799203011a36/starling_monitor/starling_monitor.rb</url>
</plugin-url>
