diff --git a/app/services/ping.rb b/app/services/ping.rb index e24fbabdc990..d99441561a53 100644 --- a/app/services/ping.rb +++ b/app/services/ping.rb @@ -7,6 +7,7 @@ def ping { 'foreman': { database: ping_database, + cache: ping_cache, }, }.merge(plugins_ping) end @@ -47,6 +48,39 @@ def ping_database } end + def ping_cache + response = {} + + if Rails.application.config.cache_store.first == :redis_cache_store + redis = Rails.cache.redis + response['servers'] = {} + + if redis.respond_to?(:nodes) + nodes = redis.nodes + else + nodes = [redis] + end + + nodes.each_with_index do |node, index| + start = Time.now + + begin + node.ping + status = STATUS_OK + rescue Redis::CannotConnectError => e + status = STATUS_FAIL + ensure + response['servers'][index] = { + status: status, + duration_ms: duration_ms(start), + } + end + end + end + + response + end + def statuses_compute_resources results = [] ComputeResource.all.index.map do |resource|