Class: Hallmonitor::Outputters::StatsdOutputter

Inherits:
Hallmonitor::Outputter show all
Defined in:
lib/hallmonitor/outputters/statsd_outputter.rb

Overview

An outputter for StatsD

Instance Attribute Summary

Attributes inherited from Hallmonitor::Outputter

#name

Instance Method Summary collapse

Constructor Details

#initialize(prefix, host = 'localhost', port = 8125, transformer = nil) ⇒ StatsdOutputter

Builds a new StatsdOutputter.

Parameters:

  • prefix (String)

    Prefix for all events output by this outputter, the prefix will be applied to all event names before sending to statsd

  • host (String) (defaults to: 'localhost')

    Statsd Host, defaults to ‘localhost’

  • port (Number) (defaults to: 8125)

    Statsd Port, defaults to 8125

  • transformer (#transform(event)) (defaults to: nil)

    An object that responds to #transform(Event). If supplied it will be passed each event and should return an event name. This is to allow for flattening any tags present in the event into a flattened name structure.

Raises:

  • if Statsd is undefined (Gem not present)



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hallmonitor/outputters/statsd_outputter.rb', line 20

def initialize(prefix, host = 'localhost', port = 8125, transformer = nil)
  unless defined?(Statsd)
    fail 'In order to use StatsdOutputter, statsd gem must be installed'
  end

  if transformer && !transformer.respond_to?(:transform)
    fail 'Supplied transformer does not respond to :transform'
  end

  super(prefix)
  @statsd = Statsd.new(host).tap { |sd| sd.namespace = name }
  @transformer = transformer
end

Instance Method Details

#process(event) ⇒ Object

Sends events to statsd instance If the event’s value field is a hash, this will send multiple events to statsd with the original name suffixed by the name of the events in the hash



38
39
40
41
42
43
44
45
46
# File 'lib/hallmonitor/outputters/statsd_outputter.rb', line 38

def process(event)
  if event.is_a?(Hallmonitor::TimedEvent)
    process_timed_event(event)
  elsif event.is_a?(Hallmonitor::GaugeEvent)
    process_gauge_event(event)
  else
    process_event(event)
  end
end