Class: OkComputer::RedisCheck

Inherits:
Check
  • Object
show all
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

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

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_configObject (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

#checkObject

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

  mark_message "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
  mark_message "Error: '#{e}'"
end

#redisObject

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_infoObject

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