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, #initialize, #process

Methods inherited from MonitorType

#alert, #initialize, #process, #run, #teardown

Constructor Details

This class inherits a constructor from MonitorType_Threshold

Instance Method Details

#extractParamsObject

Extract parameters

Parameters:

  • beanstalk (String)

    Optional connection string. Default to local

  • queue (String)

    Name of queue to monitor



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/MonitorType/Beanstalk.rb', line 11

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

       if @params[:queue].nil? then
           string = "*** Beanstalk parameter missing, queue\n"
           string = "#{string}*** :queue => <queue name>"
           raise MonitorTypeParameterMissingError.new(string)
       end
       @queue = @params[:queue]
       
       @context_sentence = "Checking number of jobs in queue, #{@queue}"
       
end

#getValueObject



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

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

#setupObject



25
26
27
# File 'lib/MonitorType/Beanstalk.rb', line 25

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