Class: BoringServices::HealthChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/boring_services/health_checker.rb

Constant Summary collapse

REDIS_INFO_KEYS =
%w[used_memory_human connected_clients keyspace_hits keyspace_misses maxmemory_human].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HealthChecker

Returns a new instance of HealthChecker.



9
10
11
12
# File 'lib/boring_services/health_checker.rb', line 9

def initialize(config)
  @config = config
  @ssh_executor = SSHExecutor.new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/boring_services/health_checker.rb', line 7

def config
  @config
end

#ssh_executorObject (readonly)

Returns the value of attribute ssh_executor.



7
8
9
# File 'lib/boring_services/health_checker.rb', line 7

def ssh_executor
  @ssh_executor
end

Instance Method Details

#check_allObject



14
15
16
17
18
19
20
# File 'lib/boring_services/health_checker.rb', line 14

def check_all
  results = {}
  config.enabled_services.each do |service|
    results[service['name']] = check_service(service)
  end
  results
end

#check_service(service) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/boring_services/health_checker.rb', line 22

def check_service(service)
  hosts = extract_hosts(service)
  return { status: 'no_host' } if hosts.empty?

  host_results = hosts.map { |host_config| check_host(service['name'], host_config) }
  {
    status: host_results.all? { |r| r[:running] } ? 'healthy' : 'unhealthy',
    hosts: host_results
  }
end