Class: OkComputer::RedisCheck
- Defined in:
- lib/ok_computer/built_in_checks/redis_check.rb
Overview
This class performs a health check on a Redis instance using the INFO command.
It reports the Redis instance’s memory usage, uptime, and number of connected clients.
Constant Summary collapse
- ConnectionFailed =
Class.new(StandardError)
Constants inherited from Check
Instance Attribute Summary collapse
-
#redis_config ⇒ Object
readonly
Returns the value of attribute redis_config.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the status of Redis.
-
#initialize(redis_config) ⇒ RedisCheck
constructor
Public: Initialize a new Redis check.
-
#redis ⇒ Object
Returns a redis instance based on configuration.
-
#redis_info ⇒ Object
Returns a hash from Redis’s INFO command.
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(redis_config) ⇒ RedisCheck
Public: Initialize a new Redis check.
redis_config - The configuration of the Redis instance.
Expects any valid configuration that can be passed to Redis.new.
See https://github.com/redis/redis-rb#getting-started
15 16 17 |
# File 'lib/ok_computer/built_in_checks/redis_check.rb', line 15 def initialize(redis_config) @redis_config = redis_config end |
Instance Attribute Details
#redis_config ⇒ Object (readonly)
Returns the value of attribute redis_config.
8 9 10 |
# File 'lib/ok_computer/built_in_checks/redis_check.rb', line 8 def redis_config @redis_config end |
Instance Method Details
#check ⇒ Object
Public: Return the status of Redis.
20 21 22 23 24 25 26 27 |
# File 'lib/ok_computer/built_in_checks/redis_check.rb', line 20 def check info = redis_info "Connected to redis, #{info['used_memory_human']} used memory, uptime #{info['uptime_in_seconds']} secs, #{info['connected_clients']} connected client(s)" rescue => e mark_failure "Error: '#{e}'" end |
#redis ⇒ Object
Returns a redis instance based on configuration
37 38 39 |
# File 'lib/ok_computer/built_in_checks/redis_check.rb', line 37 def redis @redis ||= ::Redis.new(redis_config) end |
#redis_info ⇒ Object
Returns a hash from Redis’s INFO command.
30 31 32 33 34 |
# File 'lib/ok_computer/built_in_checks/redis_check.rb', line 30 def redis_info redis.info rescue => e raise ConnectionFailed, e end |