Class: HAProxy::SocketReader
- Inherits:
-
StatsReader
- Object
- StatsReader
- HAProxy::SocketReader
- Defined in:
- lib/haproxy/socket_reader.rb
Constant Summary collapse
- TYPES =
{ :frontend => 1, :backend => 2, :server => 4 }
Instance Method Summary collapse
- #backends ⇒ Object
- #errors ⇒ Object
- #frontends ⇒ Object
- #info ⇒ Object
-
#initialize(path) ⇒ SocketReader
constructor
A new instance of SocketReader.
- #servers ⇒ Object
- #sessions ⇒ Object
- #stats(types = [:all], options = {}) ⇒ Object
Constructor Details
#initialize(path) ⇒ SocketReader
Returns a new instance of SocketReader.
8 9 10 11 |
# File 'lib/haproxy/socket_reader.rb', line 8 def initialize(path) raise ArgumentError, "Socket #{path} doesn't exists or is not a UNIX socket" unless File.exists?(path) and File.socket?(path) @path = path end |
Instance Method Details
#backends ⇒ Object
75 76 77 |
# File 'lib/haproxy/socket_reader.rb', line 75 def backends stats :frontend, :proxy => :all, :server => :all end |
#errors ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/haproxy/socket_reader.rb', line 22 def errors returning("") do |errors| send_cmd "show errors" do |line| errors << line end end end |
#frontends ⇒ Object
71 72 73 |
# File 'lib/haproxy/socket_reader.rb', line 71 def frontends stats :frontend, :proxy => :all, :server => :all end |
#info ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/haproxy/socket_reader.rb', line 13 def info returning({}) do |info| send_cmd "show info" do |line| key, value = line.split(': ') info[key.downcase.gsub('-', '_').to_sym] = value end end end |
#servers ⇒ Object
79 80 81 |
# File 'lib/haproxy/socket_reader.rb', line 79 def servers stats :server, :proxy => :all, :server => :all end |
#sessions ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/haproxy/socket_reader.rb', line 30 def sessions returning([]) do |sess| send_cmd "show sess" do |line| sess << line end end end |
#stats(types = [:all], options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/haproxy/socket_reader.rb', line 44 def stats(types=[:all], ={}) params = { :proxy => :all, :server => :all }.merge() params[:proxy] = "-1" if params[:proxy].eql?(:all) params[:server] = "-1" if params[:server].eql?(:all) types = [types] unless types.is_a?(Array) params[:type] = case when types.eql?([:all]) "-1" else types.map{ |type| TYPES[type] }.inject(:+) end cmd = "show stat #{params[:proxy]} #{params[:type]} #{params[:server]}" returning([]) do |stats| send_cmd(cmd) do |line| stats << CSVParser.parse(line) unless line.start_with?('#') end end end |