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

metrics-es-node-graphite.rb: drop invalid lines #3

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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