Sha256: 8ac005fee9c88c44469644ac9af5924b35e82e7e69337dc8951f935631731a5d

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env ruby
#
#   check-memcached-stats
#
# DESCRIPTION:
#   Check Memcached stats
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: socket
#
# USAGE:
#   #YELLOW
#
# NOTES:
#
# LICENSE:
#   Copyright 2012 AJ Christensen <aj@junglist.gen.nz>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'socket'
require 'timeout'

class MemcachedStats < Sensu::Plugin::Check::CLI
  option :host,
         short: '-h HOST',
         long: '--host HOST',
         description: 'Memcached Host to connect to',
         required: false,
         default: '127.0.0.1'

  option :port,
         short: '-p PORT',
         long: '--port PORT',
         description: 'Memcached Port to connect to',
         proc: proc(&:to_i),
         default: 11_211

  def run
    Timeout.timeout(30) do
      TCPSocket.open(config[:host], config[:port]) do |socket|
        socket.print "stats\r\n"
        socket.close_write
        socket.read
      end
    end
  rescue Timeout::Error
    warning "timed out connecting to memcached on port #{config[:port]}"
  rescue StandardError
    critical "Can't connect to port #{config[:port]}"
  else
    ok 'memcached stats protocol responded in a timely fashion'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-memcached-boutetnico-1.0.0 bin/check-memcached-stats.rb