Class: MonitorTypeBeanstalk

Inherits:
MonitorTypeThreshold show all
Defined in:
lib/monitor_type/beanstalk.rb

Overview

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

Instance Method Summary collapse

Methods inherited from MonitorTypeThreshold

#check, #initialize, #process

Methods inherited from MonitorType

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

Constructor Details

This class inherits a constructor from MonitorTypeThreshold

Instance Method Details

#derived_valueObject



26
27
28
29
30
31
# File 'lib/monitor_type/beanstalk.rb', line 26

def derived_value
  tube_stats = @beanstalk.stats_tube(@queue)
  tube_stats['current-jobs-ready']
rescue Beanstalk::NotFoundError
  0
end

#extract_paramsObject

Extract parameters

Parameters:

  • beanstalk (String)

    Optional connection string. Default to local

  • queue (String)

    Name of queue to monitor



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/monitor_type/beanstalk.rb', line 9

def extract_params
  @connection_string = @params[:beanstalk] || 'localhost:11300'

  if @params[:queue].nil?
    string = "*** Beanstalk parameter missing, queue\n" \
             '*** :queue => <queue name>'
    fail MonitorTypeParameterMissingError, string
  end
  @queue = @params[:queue]

  @context_sentence = "Checking number of jobs in queue, #{@queue}"
end

#setupObject



22
23
24
# File 'lib/monitor_type/beanstalk.rb', line 22

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