Class: Fozzie::Adapter::Datadog

Inherits:
Statsd
  • Object
show all
Defined in:
lib/fozzie/adapter/datadog.rb

Constant Summary

Constants inherited from Statsd

Statsd::BULK_DELIMETER, Statsd::DELIMETER, Statsd::RESERVED_CHARS_REGEX, Statsd::RESERVED_CHARS_REPLACEMENT, Statsd::SAFE_SEPARATOR, Statsd::TYPES

Instance Method Summary collapse

Methods inherited from Statsd

#delimeter, #format_bucket, #format_value, #host_ip, #host_port, #safe_separator, #sampled, #sampled?, #send_to_socket, #socket

Instance Method Details

#register(*stats) ⇒ Object

stats is a collection of hashes in the following format: { :bucket => stat, :value => value, :type => type, :sample_rate => sample_rate, tags => [“serviceid:fozzie”,“country:au”] }



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fozzie/adapter/datadog.rb', line 9

def register(*stats)
  metrics = stats.flatten.map do |stat|
    next if sampled?(stat[:sample_rate])

    bucket = format_bucket(stat[:bucket])
    value  = format_value(stat[:value], stat[:type], stat[:sample_rate])
    tags   = (stat[:tags] || []).map {|tag| tag.gsub(/[,\|]/, RESERVED_CHARS_REPLACEMENT)}

    result = "#{bucket}:#{value}" 
    result << "|##{tags.join(',')}" if tags.any? 
    result
  end.compact.join(BULK_DELIMETER)

  send_to_socket(metrics)
end