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) ⇒ 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

Raises:

  • if Statsd is undefined (Gem not present)



16
17
18
19
20
# File 'lib/hallmonitor/outputters/statsd_outputter.rb', line 16

def initialize(prefix, host="localhost", port=8125)
  raise "In order to use StatsdOutputter, statsd gem must be installed" unless defined?(Statsd)
  super(prefix)
  @statsd = Statsd.new(host).tap{|sd| sd.namespace = name}
end

Instance Method Details

#process(event) ⇒ Object

Sends events to statsd instance



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

def process(event)
  if(event.respond_to?(:duration))
    @statsd.timing(event.name, event.duration)
  elsif(event.respond_to?(:value))
    @statsd.gauge(event.name, event.value)
  else
    @statsd.count(event.name, event.count)
  end
end