bin/metrics-mesos.rb in sensu-plugins-mesos-1.0.0 vs bin/metrics-mesos.rb in sensu-plugins-mesos-1.1.0

- old
+ new

@@ -73,10 +73,16 @@ short: '-t TIMEOUT', long: '--timeout TIMEOUT', proc: proc(&:to_i), default: 5 + option :include_role, + description: 'Include master role in metrics', + short: '-r INCLUDE_ROLE', + long: '--host INCLUDE_ROLE', + default: 'false' + def run uri = config[:uri] case config[:mode] when 'master' port = config[:port] || MASTER_DEFAULT_PORT @@ -84,12 +90,22 @@ port = config[:port] || SLAVE_DEFAULT_PORT end scheme = "#{config[:scheme]}.mesos-#{config[:mode]}" begin r = RestClient::Resource.new("http://#{config[:server]}:#{port}#{uri}", timeout: config[:timeout]).get - JSON.parse(r).each do |k, v| + results = JSON.parse(r) + if config[:include_role] == 'true' && config[:mode] == 'master' + add_metric = if results['master/elected'] != 0.0 + 'leader.' + else + 'standby.' + end + else + add_metric = '' + end + results.each do |k, v| k_copy = k.tr('/', '.') - output([scheme, k_copy].join('.'), v) + output([scheme, add_metric + k_copy].join('.'), v) end rescue Errno::ECONNREFUSED critical "Mesos #{config[:mode]} is not responding" rescue RestClient::RequestTimeout critical "Mesos #{config[:mode]} Connection timed out"