#!/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 # 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