class DeepHealthCheck::TCPDependencyHealthCheck
Public Class Methods
new()
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 7 def initialize @type = 'tcp' @dependencies = process_dependencies fetch_dependencies_from_env end
Private Instance Methods
down()
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 47 def down { 'message': 'DOWN' } end
health_status_code()
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 26 def health_status_code faild_count = @dependencies.select { |_k, v| v == down }.count faild_count.zero? ? 200 : 503 end
process_dependencies(dependencies_list)
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 14 def process_dependencies(dependencies_list) threads = dependencies_list.map do |item| host, port = item.to_s.split(':') Thread.new do { "#{host}_#{port}" => tcp_telnet_status(host, port) } end end threads.each(&:join) threads.map(&:value).reduce(&:merge) end
tcp_telnet_status(host, port)
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 31 def tcp_telnet_status(host, port) return up if Net::Telnet.new( 'Host' => host, 'Port' => port, 'Telnetmode' => false, 'Prompt' => /^\+OK/n ) down rescue down end
up()
click to toggle source
# File lib/deep_health_check/tcp_dependency_health_check.rb, line 43 def up { 'message': 'UP' } end