Sha256: 4cea0df13007d72c78dcc876efdc45dc4944371f163ecf6d3468c00152768dcf

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

#! /usr/bin/env ruby
#
# check-beanstalk-watchers-to-buried
#
# DESCRIPTION:
#   #YELLOW
#
# OUTPUT:
#   plain-text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: beanstalk
#   gem: sensu-plugin
#
# USAGE:
#   #YELLOW
#
# NOTES:
#
# LICENSE:
#   Copyright S. Zachariah Sprackett <zac@sprackett.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'beanstalk-client'

#
# Check Beanstalk Watchers To Buried
#
class CheckBeanstalkWatchersToBuried < Sensu::Plugin::Check::CLI
  option :host,
         short: '-H HOST',
         default: 'localhost'
  option :port,
         short: '-p PORT',
         default: '11300'
  option :tube,
         short: '-t TUBE'
  option :crit,
         short: '-c CRIT_THRESHOLD',
         proc: proc(&:to_i),
         default: 0
  option :warn,
         short: '-w WARN_THRESHOLD',
         proc: proc(&:to_i),
         default: 0

  def run # rubocop:disable all
    unknown 'Tube was not set' unless config[:tube]
    begin
      beanstalk = Beanstalk::Connection.new(
        "#{config[:host]}:#{config[:port]}"
      )
    rescue => e
      critical "Failed to connect: (#{e})"
    end

    begin
      stats = beanstalk.stats_tube(config[:tube])
      watchers = stats['current-watching'].to_i
      buried = stats['current-jobs-buried'].to_i
    rescue Beanstalk::NotFoundError
      warning "Tube #{config[:tube]} not found"
    end
    # #YELLOW
    unless watchers # rubocop:disable IfUnlessModifier
      watchers = 0
    end

    if config[:crit] || (buried - watchers) > config[:crit]
      critical "Exceeded buried jobs by threshold of #{config[:crit]} (#{watchers}/#{buried})"
    elsif config[:warn] || (buried - watchers) > config[:warn]
      warning "Exceeded buried jobs by threshold of #{config[:warn]} (#{watchers}/#{buried})"
    else
      ok "#{buried} buried jobs and #{watchers} watchers found."
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensu-plugins-beanstalk-0.0.1 bin/check-beanstalk-watchers-to-buried.rb
sensu-plugins-beanstalk-0.0.1.alpha.2 bin/check-beanstalk-watchers-to-buried.rb
sensu-plugins-beanstalk-0.0.1.alpha.1 bin/check-beanstalk-watchers-to-buried.rb