haproxystats 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/haproxystats/socket.rb +20 -11
- metadata +1 -1
data/lib/haproxystats/socket.rb
CHANGED
@@ -16,19 +16,28 @@ class HAProxySocket
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Open a socket, run a command, collect output and close
|
19
|
-
def run(command)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
def run(command, try_again=true)
|
20
|
+
begin
|
21
|
+
sock = UNIXSocket.new @location
|
22
|
+
sock.puts command
|
23
|
+
out = ''
|
24
|
+
first_char = sock.read 2
|
25
|
+
if first_char == '# '
|
26
|
+
out = CSV.parse(sock.read)
|
27
|
+
sock.close
|
28
|
+
return out
|
29
|
+
end
|
30
|
+
out = first_char + sock.read
|
26
31
|
sock.close
|
27
|
-
|
32
|
+
out
|
33
|
+
rescue Errno::EPIPE
|
34
|
+
if try_again
|
35
|
+
sock.close
|
36
|
+
run(command, try_again=false)
|
37
|
+
else
|
38
|
+
raise IOError, "IO Error 32 with socket"
|
39
|
+
end
|
28
40
|
end
|
29
|
-
out = first_char + sock.read
|
30
|
-
sock.close
|
31
|
-
out
|
32
41
|
end
|
33
42
|
|
34
43
|
# Show info from haproxy
|