Module: FFWD::Plugin::Datadog::Utils
- Defined in:
- lib/ffwd/plugin/datadog/utils.rb
Class Method Summary collapse
-
.make_metrics(buffer) ⇒ Object
groups similar metadata and escapes them using the suite of safe_* functions available.
-
.safe_entry(entry) ⇒ Object
make safe entry out of available information.
- .safe_string(string) ⇒ Object
- .safe_tags(tags) ⇒ Object
Class Method Details
.make_metrics(buffer) ⇒ Object
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 (||=).
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ffwd/plugin/datadog/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(:points => [])) group[:points] << [m.time.to_i, m.value] end return {:series => groups.values} end |
.safe_entry(entry) ⇒ Object
make safe entry out of available information.
36 37 38 39 40 41 |
# File 'lib/ffwd/plugin/datadog/utils.rb', line 36 def self.safe_entry entry host = entry[:host] metric = entry[:name] = entry[:attributes] {:host => host, :metric => safe_string(metric), :tags => ()} end |
.safe_string(string) ⇒ Object
43 44 45 46 47 |
# File 'lib/ffwd/plugin/datadog/utils.rb', line 43 def self.safe_string string string = string.to_s string = string.gsub " ", "_" string.gsub ":", "_" end |
.safe_tags(tags) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ffwd/plugin/datadog/utils.rb', line 49 def self. safe = [] .each do |key, value| safe_key = safe_string(key) safe_value = safe_string(value) safe << "#{safe_key}:#{safe_value}" end return safe end |