Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
metrics-es-node-graphite.rb: drop invalid lines (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
boutetnico committed Dec 10, 2020
1 parent ed09cf1 commit 6a30b34
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions bin/metrics-es-node-graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6a30b34

Please sign in to comment.