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



23
24
25
26
27
28
29
# File 'lib/big_brother/health_fetcher.rb', line 23

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



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

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

.interpol_status(interpol_node, fwmark) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/big_brother/health_fetcher.rb', line 13

def self.interpol_status(interpol_node, fwmark)
  url = "http://#{interpol_node.address}:#{interpol_node.port}/fwmark/#{fwmark}"

  BigBrother.logger.debug("Fetching health from #{url}")
  response = EventMachine::HttpRequest.new(url).get
  response.response_header.status == 200 ? JSON.parse(response.response) : []
rescue JSON::ParserError
  []
end