class Metrics::Drivers::Statsd
Attributes
client[R]
source_prefix[R]
template[R]
Public Class Methods
new(client, template, source_prefix)
click to toggle source
# File lib/metrics/drivers/statsd.rb, line 5 def initialize(client, template, source_prefix) @client = client # The statsd client @template = template # The template for the metric name @source_prefix = source_prefix # Source prefix end
Public Instance Methods
emit(instrumenter)
click to toggle source
# File lib/metrics/drivers/statsd.rb, line 18 def emit(instrumenter) name = name_for(instrumenter) value = instrumenter.value case instrumenter.type when 'histogram' client.histogram(name, value) when 'measure', 'sample' if instrumenter.units == 'ms' client.timing(name, value) else client.gauge(name, value) end when 'count' client.count(name, value) else raise ArgumentError.new("unsupported instrumenter type for statsd: '%s'" % instrumenter.type) end end
write(*instrumenters)
click to toggle source
# File lib/metrics/drivers/statsd.rb, line 11 def write(*instrumenters) instrumenters.each do |instrumenter| emit(instrumenter) end instrumenters end
Private Instance Methods
name_for(instrumenter)
click to toggle source
# File lib/metrics/drivers/statsd.rb, line 40 def name_for(instrumenter) template.gsub('{{name}}', instrumenter.metric).gsub('{{source}}', source(instrumenter)) end
source(instrumenter)
click to toggle source
# File lib/metrics/drivers/statsd.rb, line 44 def source(instrumenter) [source_prefix, instrumenter.source].compact.join('.') end