diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 2f583a7..3e85c31 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -142,7 +142,7 @@ def get_es_resource(resource) timeout: config[:timeout], headers: headers) end - ::JSON.parse(r.get) + JSON.parse(r.get) rescue Errno::ECONNREFUSED warning 'Connection refused' rescue RestClient::RequestTimeout @@ -264,7 +264,9 @@ def run node['indices'].each do |type, index| index.each do |k, v| # #YELLOW - unless k =~ /(_time$)/ || v =~ /\d+/ + if k.end_with? 'is_throttled' + metrics["indices.#{type}.#{k}"] = true?(v) ? 1 : 0 + elsif !(k =~ /(_time$)/ || v =~ /\d+/) metrics["indices.#{type}.#{k}"] = v end end @@ -306,16 +308,47 @@ def run if fs_stats node['fs'].each do |fs, fs_value| unless fs =~ /(timestamp|data)/ - fs_value.each do |k, v| - metrics["fs.#{fs}.#{k}"] = v + metrics_fs = hash_to_dotted_path(fs_value, "#{fs}.") + metrics_fs.each do |k, v| + metrics["fs.#{k}"] = v end end end end metrics.each do |k, v| - output([config[:scheme], k].join('.'), v, timestamp) + if v.is_a? Numeric + output([config[:scheme], k].join('.'), v, timestamp) + end end ok end end + +def hash_to_dotted_path(hash, path = '') + hash.each_with_object({}) do |(k, v), ret| + key = path + k.to_s + if v.is_a? Hash + ret.merge! hash_to_dotted_path(v, "#{key}.") + elsif v.is_a? Array + v.each do |element| + if element['device_name'] + key2 = "#{key}.#{element['device_name']}" + ret.merge! hash_to_dotted_path(element, "#{key2}.") + end + end + else + ret[key] = v + end + end +end + +def true?(obj) + if obj.to_s == 'true' + true + elsif obj.to_s == 'false' + false + else + "#{obj} is not a truthy value, please open an issue with this output so we can fix it" + end +end \ No newline at end of file