class HealthMonitor::Providers::Redis
Private Class Methods
as_connection_pool(connection)
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 27 def as_connection_pool(connection) ConnectionPool.new(size: CONNECTION_POOL_SIZE) { connection } end
Public Instance Methods
check!()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 32 def check! check_values! check_max_used_memory! rescue Exception => e raise RedisException.new(e.message) end
Private Instance Methods
bytes_to_megabytes(bytes)
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 80 def bytes_to_megabytes(bytes) (bytes.to_f / 1024 / 1024).round end
check_max_used_memory!()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 54 def check_max_used_memory! return unless configuration.max_used_memory return if used_memory_mb <= configuration.max_used_memory raise "#{used_memory_mb}Mb memory using is higher than #{configuration.max_used_memory}Mb maximum expected" end
check_values!()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 45 def check_values! time = Time.now.to_formatted_s(:rfc2822) redis.with { |conn| conn.set(key, time) } fetched = redis.with { |conn| conn.get(key) } raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time end
configuration_class()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 41 def configuration_class ::HealthMonitor::Providers::Redis::Configuration end
key()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 61 def key @key ||= ['health', request.try(:remote_ip)].join(':') end
redis()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 65 def redis @redis = if configuration.connection if configuration.connection.is_a?(ConnectionPool) configuration.connection else ConnectionPool.new(size: CONNECTION_POOL_SIZE) { configuration.connection } end elsif configuration.url ConnectionPool.new(size: CONNECTION_POOL_SIZE) { ::Redis.new(url: configuration.url) } else ConnectionPool.new(size: CONNECTION_POOL_SIZE) { ::Redis.new } end end
used_memory_mb()
click to toggle source
# File lib/health_monitor/providers/redis.rb, line 84 def used_memory_mb bytes_to_megabytes(redis.with { |conn| conn.info['used_memory'] }) end