diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b5625..ad30e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) ## [Unreleased] +### Changed +- metrics-es-node-graphite.rb: exclude non-numeric data from results (@boutetnico) ## [3.0.0] - 2018-12-17 ### Breaking Changes diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 26ba22a..0e6320f 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -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