Class: MonitorType_Beanstalk

Inherits:
MonitorType_Threshold show all
Defined in:
lib/MonitorType/Beanstalk.rb

Overview

A Beanstalk class for checking how many msgs are in a Queue

Instance Method Summary collapse

Methods inherited from MonitorType_Threshold

#check

Methods inherited from MonitorType

#alert, #run

Constructor Details

#initialize(params) ⇒ MonitorType_Beanstalk

Constructor: Extract parameters



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/MonitorType/Beanstalk.rb', line 15

def initialize( params )
  super( params )
       @connection_string = params[:beanstalk] || "localhost:11300"

       if params[:queue].nil? then
           puts "*** Beanstalk parameter missing, queue"
           puts "*** :queue => <queue name>"
           abort
       end
       @queue = params[:queue]
  self.sanitise
       rescue MonitorTypeExceptionHandled => e
       puts e.message
       abort()
end

Instance Method Details

#processObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/MonitorType/Beanstalk.rb', line 31

def process
       count = 0
       begin
       tubeStats = @beanstalk.stats_tube(@queue)
       count = tubeStats["current-jobs-ready"]
       rescue Beanstalk::NotFoundError=>e
       end

  self.check( count, "Checking number of jobs in queue, #{@queue}" )
end

#sanitiseObject



7
8
9
# File 'lib/MonitorType/Beanstalk.rb', line 7

def sanitise
       @beanstalk = Beanstalk::Pool.new([@connection_string])
end