Class: Consul::Client::Status

Inherits:
Base
  • Object
show all
Defined in:
lib/consul/client/status.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #is_reachable

Constructor Details

This class inherits a constructor from Consul::Client::Base

Instance Method Details

#build_url(suffix) ⇒ Object



34
35
36
# File 'lib/consul/client/status.rb', line 34

def build_url(suffix)
  "#{base_versioned_url}/status/#{suffix}"
end

#leaderObject

Public: This endpoint is used to get the Raft leader for the datacenter in which the agent is running

Reference: www.consul.io/docs/agent/http/status.html

Returns: Address, host:port.



14
15
16
17
18
19
# File 'lib/consul/client/status.rb', line 14

def leader
  resp = RestClient.get leader_url
  return resp.body.slice(1, resp.body.length-2) if resp.code == 200
  logger.warn("Unable to get leader. Resp code: #{resp.code} Resp message: #{resp.body}")
  nil
end

#peersObject

Public: This endpoint retrieves the Raft peers for the datacenter in which the the agent is running

Reference: www.consul.io/docs/agent/http/status.html

Returns: List of addresses.



27
28
29
30
31
32
# File 'lib/consul/client/status.rb', line 27

def peers
  resp = RestClient.get peers_url
  return JSON.parse(resp.body) if resp.code == 200
  logger.warn("Unable to get peers. Resp code: #{resp.code} Resp message: #{resp.body}")
  nil
end