onering-report-plugins 0.0.34 → 0.0.35
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.
@@ -1,11 +1,14 @@
|
|
1
1
|
# Onering Facts - HAProxy Stats
|
2
2
|
# provides collection of statistics from HAProxy
|
3
3
|
#
|
4
|
+
require 'set'
|
4
5
|
require 'socket'
|
5
6
|
|
6
7
|
haproxy = nil
|
8
|
+
sockets_seen = Set.new()
|
7
9
|
|
8
|
-
|
10
|
+
# find all haproxy configs, ensuring haproxy.cfg is always front of the line
|
11
|
+
Dir["/etc/haproxy/*.cfg"].sort{|a,b| (b == 'haproxy.cfg' ? 1 : a<=>b) }.each do |cfg|
|
9
12
|
haproxy ||= []
|
10
13
|
pools = {}
|
11
14
|
cfg_data = (File.read(cfg).lines rescue [])
|
@@ -13,12 +16,16 @@ Dir["/etc/haproxy/*.cfg"].each do |cfg|
|
|
13
16
|
description = (cfg_data.select{|i| i =~ /^\s* description / }.first.strip.split(' ',2).last.gsub('"','') rescue nil)
|
14
17
|
socket = (cfg_data.select{|i| i =~ /^\s* stats socket / }.first.strip.split(' ')[2] rescue nil)
|
15
18
|
|
16
|
-
|
19
|
+
# stats socket must be present in the config, a real file, and not have been seen before
|
20
|
+
if not socket.nil? and File.exists?(socket) and not sockets_seen.include?(socket)
|
21
|
+
sockets_seen << socket
|
17
22
|
stats = UNIXSocket.new(socket)
|
18
23
|
stats.puts("show stat")
|
19
24
|
|
20
25
|
instance = {
|
21
26
|
:name => File.basename(cfg, '.cfg'),
|
27
|
+
:socket => socket,
|
28
|
+
:path => cfg,
|
22
29
|
:description => description,
|
23
30
|
:pools => []
|
24
31
|
}
|