module FFWD::Plugin::KairosDB::Utils
Public Class Methods
make_metrics(buffer)
click to toggle source
groups similar metadata and escapes them using the suite of safe_* functions available.
Should prevent unecessary invocations of safe_entry
by only adding new groups of the source metric differs (||=).
# File lib/ffwd/plugin/kairosdb/utils.rb, line 23 def self.make_metrics buffer groups = {} buffer.each do |m| entry = {:host => m.host, :name => m.key, :attributes => m.attributes} group = (groups[entry] ||= safe_entry(entry).merge(:datapoints => [])) group[:datapoints] << [(m.time.to_f * 1000).to_i, m.value] end return groups.values end
safe_entry(entry)
click to toggle source
make safe entry out of available information.
# File lib/ffwd/plugin/kairosdb/utils.rb, line 36 def self.safe_entry entry name = entry[:name] host = entry[:host] attributes = entry[:attributes] {:name => safe_string(name), :tags => safe_tags(host, attributes)} end
safe_string(string)
click to toggle source
Warning: These are the ‘bad’ characters I’ve been able to reverse engineer so far.
# File lib/ffwd/plugin/kairosdb/utils.rb, line 45 def self.safe_string string string = string.to_s string = string.gsub " ", "/" string.gsub ":", "_" end