Module: LitmusPaper::HaproxyUtil
- Included in:
- Dependency::HaproxyBackends, Metric::HaproxyBackendsHealth
- Defined in:
- lib/litmus_paper/haproxy_util.rb
Instance Method Summary collapse
- #_fetch_stats(socket, timeout) ⇒ Object
- #_get_stats(socket, timeout) ⇒ Object
- #_parse_stats(csv) ⇒ Object
- #find_backend(socket, timeout, cluster) ⇒ Object
- #find_servers(socket, timeout, cluster) ⇒ Object
Instance Method Details
#_fetch_stats(socket, timeout) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
19 20 21 |
# File 'lib/litmus_paper/haproxy_util.rb', line 19 def _get_stats(socket, timeout) _parse_stats(_fetch_stats(socket, timeout)) end |
#_parse_stats(csv) ⇒ Object
32 33 34 35 36 |
# 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) ⇒ Object
12 13 14 15 16 17 |
# 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) ⇒ Object
5 6 7 8 9 10 |
# 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 |