Class: HAProxyManager::Instance
- Inherits:
-
Object
- Object
- HAProxyManager::Instance
- Defined in:
- lib/haproxy_manager/instance.rb
Instance Method Summary collapse
- #backends ⇒ Object
-
#disable(serverid, backend = nil) ⇒ Object
Diables a server in the server in a backend for maintenance.
-
#enable(serverid, backend = nil) ⇒ Object
Enables a server in the server in a backend.
- #info ⇒ Object
-
#initialize(socket) ⇒ Instance
constructor
A new instance of Instance.
-
#reset_counters(option = "") ⇒ Object
resets Haproxy counters.
- #servers(backend = nil) ⇒ Object
Constructor Details
#initialize(socket) ⇒ Instance
Returns a new instance of Instance.
4 5 6 7 8 9 |
# File 'lib/haproxy_manager/instance.rb', line 4 def initialize(socket) @socket = HAPSocket.new(socket) @print_response = Proc.new {|response| puts response} backends = @socket.execute( "show stat -1 4 -1" )[1..-1].collect{|item| item.split(",")[0..1]} @backends = backends.inject({}){|hash, items| (hash[items[0]] ||=[]) << items[1]; hash} end |
Instance Method Details
#backends ⇒ Object
28 29 30 |
# File 'lib/haproxy_manager/instance.rb', line 28 def backends @backends.keys end |
#disable(serverid, backend = nil) ⇒ Object
Diables a server in the server in a backend for maintenance. If backend is not specified then all the backends in which the serverid exists are disabled. A disabled server shows up as in Maintance mode.
14 15 16 17 18 |
# File 'lib/haproxy_manager/instance.rb', line 14 def disable(serverid, backend = nil) all_servers(serverid, backend).each do |item| @socket.execute "disable server #{item[0]}/#{item[1]}", &@print_response end end |
#enable(serverid, backend = nil) ⇒ Object
Enables a server in the server in a backend. If backend is not specified then all the backends in which the serverid exists are enabled.
22 23 24 25 26 |
# File 'lib/haproxy_manager/instance.rb', line 22 def enable(serverid, backend = nil) all_servers(serverid, backend).each do |item| @socket.execute "enable server #{item[0]}/#{item[1]}", &@print_response end end |
#info ⇒ Object
32 33 34 |
# File 'lib/haproxy_manager/instance.rb', line 32 def info @socket.execute( "show info").inject({}){|hash, item| x = item.split(":"); hash.merge(x[0].strip => x[1].strip)} end |
#reset_counters(option = "") ⇒ Object
resets Haproxy counters. If no option is specified backend and frontend counters are cleared, but cumulative counters are not cleared. The cumulative counters can be cleared by passing the option of all to the method, in that case all the counters are cleared. This is similar to a restart. This is useful to reset stats after for example an incident.
44 45 46 |
# File 'lib/haproxy_manager/instance.rb', line 44 def reset_counters(option = "") @socket.execute "clear counters {option}", &@print_response end |
#servers(backend = nil) ⇒ Object
36 37 38 |
# File 'lib/haproxy_manager/instance.rb', line 36 def servers(backend = nil) backend.nil? ? @backends.values.flatten : @backends[backend] end |