bin/metrics-haproxy.rb in sensu-plugins-haproxy-0.0.5 vs bin/metrics-haproxy.rb in sensu-plugins-haproxy-0.1.0
- old
+ new
@@ -78,11 +78,11 @@
option :backends,
description: 'comma-separated list of backends to fetch stats from. Default is all backends',
short: '-f BACKEND1[,BACKEND2]',
long: '--backends BACKEND1[,BACKEND2]',
proc: proc { |l| l.split(',') },
- default: [] # an empty list means show all backends
+ default: [] # an empty list means show all backends
option :server_metrics,
description: 'Add metrics for backend servers',
boolean: true,
long: '--server-metrics',
@@ -139,10 +139,11 @@
if out.to_s.length.zero?
warning "Unable to fetch stats from haproxy after #{config[:retries]} attempts"
end
+ up_by_backend = {}
parsed = CSV.parse(out)
parsed.shift
parsed.each do |line|
if config[:backends].length > 0
next unless config[:backends].include? line[0]
@@ -173,9 +174,19 @@
output "#{config[:scheme]}.#{line[0]}.response_time", line[60]
output "#{config[:scheme]}.#{line[0]}.average_time", line[61]
elsif config[:server_metrics]
output "#{config[:scheme]}.#{line[0]}.#{line[1]}.session_total", line[7]
end
+
+ if line[1] != 'BACKEND' && !line[1].nil?
+ up_by_backend[line[0]] ||= 0
+ up_by_backend[line[0]] += (line[17] == 'UP') ? 1 : 0
+ end
end
+
+ up_by_backend.each_pair do |backend, count|
+ output "#{config[:scheme]}.#{backend}.num_up", count
+ end
+
ok
end
end