class FFWD::MetricEmitter
Used to emit metrics to an ‘output’ channel
Can take two parts of a configuration ‘base’ and ‘opts’ to decide which metadata emitted metrics should be decorated with.
Public Class Methods
build(output, base, opts)
click to toggle source
# File lib/ffwd/metric_emitter.rb, line 25 def self.build output, base, opts host = opts[:host] || base[:host] || FFWD.current_host tags = FFWD.merge_sets base[:tags], opts[:tags] attributes = FFWD.merge_hashes base[:attributes], opts[:attributes] new output, host, tags, attributes end
new(output, host, tags, attributes)
click to toggle source
# File lib/ffwd/metric_emitter.rb, line 32 def initialize output, host, tags, attributes @output = output @host = host @tags = tags @attributes = attributes end
Public Instance Methods
emit(d)
click to toggle source
# File lib/ffwd/metric_emitter.rb, line 39 def emit d d[:time] ||= Time.now d[:host] ||= @host if @host d[:fixed_tags] = @tags d[:fixed_attr] = @attributes d[:value] = nil if (v = d[:value] and v.is_a?(Float) and v.nan?) @output.metric Metric.make(d) rescue => e log.error "Failed to emit metric", e end