Sha256: bbef53846251aa9f2060b041aacc4e7c2606416e3fc5b76d7945bba406659761
Contents?: true
Size: 1.34 KB
Versions: 5
Compression:
Stored size: 1.34 KB
Contents
require 'csv' module LitmusPaper module Dependency class HaproxyBackends def initialize(domain_socket, cluster, options = {}) @domain_socket = domain_socket @cluster = cluster @timeout = options.fetch(:timeout_seconds, 2) end def available? stats = _parse_stats(_fetch_stats) backend = _find_backend(stats, @cluster) if backend['status'] != 'UP' LitmusPaper.logger.info("HAproxy available check failed, #{@cluster} backend is #{backend['status']}") return false end return true rescue Timeout::Error LitmusPaper.logger.info("HAproxy available check timed out for #{@cluster}") false end def to_s "Dependency::HaproxyBackends(#{@domain_socket}, #{@cluster})" end def _find_backend(stats, cluster) stats.detect do |line| line['# pxname'] == cluster && line['svname'] == 'BACKEND' end end def _parse_stats(csv) stats = CSV.parse(csv) headers = stats.shift stats.map { |stat| Hash[headers.zip(stat)] } end def _fetch_stats Timeout.timeout(@timeout) do UNIXSocket.open(@domain_socket) do |socket| socket.send("show stat\n", 0) socket.read end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems