Class: Hallmonitor::Outputters::DogstatsdOutputter

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

Overview

An outputter for Dogstatsd

Instance Attribute Summary

Attributes inherited from Hallmonitor::Outputter

#name

Instance Method Summary collapse

Constructor Details

#initialize(prefix, host = '127.0.0.1', port = 8125, tags: {}) ⇒ DogstatsdOutputter

Builds a new DogstatsdOutputter.

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: '127.0.0.1')

    Datadog Host, defaults to ‘127.0.0.1’

  • port (Number) (defaults to: 8125)

    Datadog Port, defaults to 8125

Raises:

  • if Datadog::Statsd is undefined (Gem not present)



16
17
18
19
20
21
22
23
24
# File 'lib/hallmonitor/outputters/dogstatsd_outputter.rb', line 16

def initialize(prefix, host = '127.0.0.1', port = 8125, tags: {})
  unless defined?(Datadog::Statsd)
    fail 'In order to use DogstatsdOutputter, dogstatsd-ruby gem must be installed'
  end

  super(prefix)
  @tags = {}.merge(tags)
  @statsd = Datadog::Statsd.new(host).tap { |sd| sd.namespace = name }
end

Instance Method Details

#process(event) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/hallmonitor/outputters/dogstatsd_outputter.rb', line 35

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

#process_tags(tags) ⇒ 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



31
32
33
# File 'lib/hallmonitor/outputters/dogstatsd_outputter.rb', line 31

def process_tags(tags)
  @tags.merge(tags).map {|key, value| "#{key}:#{value}"}
end