Sha256: c4010bab3ceeaf989b1818887a5b89b7142c1a6b8dd2f0ddcda8c53a6a5d7359

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
#
# check-unicorn-queue
#
# DESCRIPTION:
#   This plugin checks the queue of Unicorn (a Rack HTTP server)
#
# OUTPUT:
#   plain-text
#
# PLATFORMS:
#   linux
#   bsd
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: raindrops
#
# USAGE:
#   check-unicorn-queue.rb -w 20 -c 50 -a 127.0.0.1:8080
#
# LICENSE:
#   Nathan Williams <nath.e.will@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.

require 'sensu-plugin/check/cli'
require 'raindrops'

class CheckUnicornQueue < Sensu::Plugin::Check::CLI
  option :addr,
         short: '-a address',
         description: 'tcp address and port (e.g. 127.0.0.1:8080)'

  option :socket,
         short: '-s socket',
         description: 'path to unix socket (e.g. /run/unicorn.sock)'

  option :warn,
         short: '-w warn',
         proc: proc(&:to_i),
         description: 'request queue warn threshold'

  option :critical,
         short: '-c critical',
         proc: proc(&:to_i),
         description: 'request queue critical threshold'

  def run
    @queued = queued
    unknown "QUEUE STATUS - #{@queued.inspect}" unless @queued
    critical "#{@queued} QUEUED" if @queued >= config[:critical]
    warn "#{@queued} QUEUED" if @queued >= config[:warn]
    ok "#{@queued} QUEUED"
  end

  def queued
    if config[:addr]
      Raindrops::Linux
        .tcp_listener_stats(config[:addr].split(','))[0].queued
    elsif config[:socket]
      Raindrops::Linux
        .unix_listener_stats(config[:socket].split(','))[0].queued
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensu-plugins-unicorn-1.0.1 bin/check-unicorn-queue.rb
sensu-plugins-unicorn-1.0.0 bin/check-unicorn-queue.rb
sensu-plugins-unicorn-0.0.4 bin/check-unicorn-queue.rb