-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcheck-redis-memory.rb
executable file
·48 lines (42 loc) · 1.56 KB
/
check-redis-memory.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
#
# Checks Redis INFO stats and limits values
# ===
#
# Copyright (c) 2012, Panagiotis Papadomitsos <[email protected]>
#
# 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 RedisChecks < Sensu::Plugin::Check::CLI
include RedisClientOptions
option :warn_mem,
short: '-w KB',
long: '--warnmem KB',
description: "Allocated KB of Redis memory on which we'll issue a WARNING",
proc: proc(&:to_i),
required: true
option :crit_mem,
short: '-c KB',
long: '--critmem KB',
description: "Allocated KB of Redis memory on which we'll issue a CRITICAL",
proc: proc(&:to_i),
required: true
def run
redis = Redis.new(default_redis_options)
used_memory = redis.info.fetch('used_memory').to_i.div(1024)
warn_memory = config[:warn_mem]
crit_memory = config[:crit_mem]
if used_memory >= crit_memory
critical "Redis running on #{config[:host]}:#{config[:port]} is above the CRITICAL limit: #{used_memory}KB used / #{crit_memory}KB limit"
elsif used_memory >= warn_memory
warning "Redis running on #{config[:host]}:#{config[:port]} is above the WARNING limit: #{used_memory}KB used / #{warn_memory}KB limit"
else
ok "Redis memory usage: #{used_memory}KB is below defined limits"
end
rescue StandardError
send(config[:conn_failure_status], "Could not connect to Redis server on #{redis_endpoint}")
end
end