Class: Nerve::ServiceCheck::HttpServiceCheck

Inherits:
BaseServiceCheck show all
Defined in:
lib/nerve/service_watcher/http.rb

Instance Method Summary collapse

Methods inherited from BaseServiceCheck

#catch_errors, #up?

Methods included from Logging

configure_logger_for, #log, logger_for

Methods included from Utils

#safe_run

Constructor Details

#initialize(opts = {}) ⇒ HttpServiceCheck

Returns a new instance of HttpServiceCheck.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nerve/service_watcher/http.rb', line 8

def initialize(opts={})
  super

  %w{port uri}.each do |required|
    raise ArgumentError, "missing required argument #{required} in http check" unless
      opts[required]
    instance_variable_set("@#{required}",opts[required])
  end

  @host        = opts['host'] || '127.0.0.1'
  @ssl         = opts['ssl']  || false

  @read_timeout = opts['read_timeout'] || @timeout
  @open_timeout = opts['open_timeout'] || 0.2
  @ssl_timeout  = opts['ssl_timeout']  || 0.2

  @name        = "http-#{@host}:#{@port}#{@uri}"
end

Instance Method Details

#checkObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nerve/service_watcher/http.rb', line 27

def check
  log.debug "running health check #{@name}"

  connection = get_connection
  response = connection.get(@uri)
  code = response.code.to_i

  if code >= 200 and code < 300
    log.debug "nerve: check #{@name} got response code #{code} with body \"#{response.body}\""
    return true
  else
    log.error "nerve: check #{@name} got response code #{code} with body \"#{response.body}\""
    return false
  end
end