module LitmusPaper::HaproxyUtil

Public Instance Methods

_fetch_stats(socket, timeout) click to toggle source
# File lib/litmus_paper/haproxy_util.rb, line 23
def _fetch_stats(socket, timeout)
  Timeout.timeout(timeout) do
    UNIXSocket.open(socket) do |socket|
      socket.send("show stat\n", 0)
      socket.read
    end
  end
end
_get_stats(socket, timeout) click to toggle source
# File lib/litmus_paper/haproxy_util.rb, line 19
def _get_stats(socket, timeout)
  _parse_stats(_fetch_stats(socket, timeout))
end
_parse_stats(csv) click to toggle source
# File lib/litmus_paper/haproxy_util.rb, line 32
def _parse_stats(csv)
  stats = CSV.parse(csv)
  headers = stats.shift
  stats.map { |stat| Hash[headers.zip(stat)] }
end
find_backend(socket, timeout, cluster) click to toggle source
# File lib/litmus_paper/haproxy_util.rb, line 12
def find_backend(socket, timeout, cluster)
  stats = _get_stats(socket, timeout)
  stats.detect do |line|
    line['# pxname'] == cluster && line['svname'] == 'BACKEND'
  end
end
find_servers(socket, timeout, cluster) click to toggle source
# File lib/litmus_paper/haproxy_util.rb, line 5
def find_servers(socket, timeout, cluster)
  stats = _get_stats(socket, timeout)
  stats.select do |line|
    line['# pxname'] == cluster && line['svname'] !~ /BACKEND|FRONTEND/
  end
end