Sha256: 6af41f86cf93c3e73c768bf5d2a49967390796f3069d25645254e3e0e342b726

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: false

#
#   check-redis-connection.rb
#
# DESCRIPTION:
#   This plugin checks the number of connections available on redis
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#   check-redis-connections-available.rb -c COUNT -w COUNT -h HOST
#
# LICENSE:
#   Copyright Adrien Waksberg <adrien.waksberg@doctolib.fr>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'redis'
require_relative '../lib/redis_client_options'

class RedisConnectionsAvailable < Sensu::Plugin::Check::CLI
  include RedisClientOptions

  option :critical,
         short: '-c COUNT',
         long: '--critical COUNT',
         description: 'COUNT critical threshold for number of connections available',
         proc: proc(&:to_i),
         required: true

  option :warning,
         short: '-w COUNT',
         long: '--warning COUNT',
         description: 'COUNT warning threshold for number of connections available',
         proc: proc(&:to_i),
         required: true

  def run
    redis = Redis.new(default_redis_options)
    maxclients = redis.config('get', 'maxclients').last.to_i
    clients = redis.info.fetch('connected_clients').to_i
    conn_available = maxclients - clients

    if conn_available <= config[:critical]
      critical "Only #{conn_available} connections left available (#{clients}/#{maxclients})"
    elsif conn_available <= config[:warning]
      warning "Only #{conn_available} connections left available (#{clients}/#{maxclients})"
    else
      ok "There are #{conn_available} connections available (#{clients}/#{maxclients})"
    end
  rescue StandardError
    send(config[:conn_failure_status], "Could not connect to Redis server on #{redis_endpoint}")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensu-plugins-redis-5.0.0 bin/check-redis-connections-available.rb
sensu-plugins-redis-4.1.0 bin/check-redis-connections-available.rb
sensu-plugins-redis-4.0.0 bin/check-redis-connections-available.rb