Class: OkComputer::PingCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/built_in_checks/ping_check.rb

Overview

Performs a health check by making a TCPSocket request to the host and port. A non-error response is considered passing.

Direct Known Subclasses

ActionMailerCheck

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(host, port, request_timeout = 5) ⇒ PingCheck

Public: Initialize a new ping check.

host - the hostname port - the port, as a string request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/ok_computer/built_in_checks/ping_check.rb', line 14

def initialize(host, port, request_timeout = 5)
  raise ArgumentError if host.blank? || port.blank?
  self.host = host
  self.port = port
  self.request_timeout = request_timeout.to_i
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/ok_computer/built_in_checks/ping_check.rb', line 7

def host
  @host
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/ok_computer/built_in_checks/ping_check.rb', line 7

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



7
8
9
# File 'lib/ok_computer/built_in_checks/ping_check.rb', line 7

def request_timeout
  @request_timeout
end

Instance Method Details

#checkObject

Public: Return the status of the Ping check



22
23
24
25
26
27
28
# File 'lib/ok_computer/built_in_checks/ping_check.rb', line 22

def check
  tcp_socket_request
  mark_message "Ping check to #{host}:#{port} successful"
rescue => e
  mark_message "Error: '#{e}'"
  mark_failure
end