Class: BigBrother::HealthFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/big_brother/health_fetcher.rb

Class Method Summary collapse

Class Method Details

._parse_health(response) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/big_brother/health_fetcher.rb', line 11

def self._parse_health(response)
  if response.response_header.has_key?('X_HEALTH')
    response.response_header['X_HEALTH'].to_i
  else
    response.response.slice(/Health: (\d+)/, 1).to_i
  end
end

.current_health(address, port, path) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/big_brother/health_fetcher.rb', line 3

def self.current_health(address, port, path)
  url = "http://#{address}:#{port}#{path}"

  BigBrother.logger.debug("Fetching health from #{url}")
  response = EventMachine::HttpRequest.new(url).get
  response.response_header.status == 200 ? _parse_health(response) : 0
end