Class: OkComputer::PingCheck
- 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
Constant Summary collapse
- ConnectionFailed =
Class.new(StandardError)
Constants inherited from Check
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the status of the Ping check.
-
#initialize(host, port, request_timeout = 5) ⇒ PingCheck
constructor
Public: Initialize a new ping check.
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.
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
#host ⇒ Object
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 |
#port ⇒ Object
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_timeout ⇒ Object
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
#check ⇒ Object
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 "Ping check to #{host}:#{port} successful" rescue => e "Error: '#{e}'" mark_failure end |