Class: SenorArmando::Plugins::StatsdSender

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/senor_armando/plugins/statsd_plugin.rb

Overview

Sends metrics to a remote statsd-compatible server

Constant Summary collapse

DEFAULT_HOST =
'127.0.0.1'
DEFAULT_PORT =
8125
DEFAULT_FRAC =
1.0

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StatsdSender

Returns a new instance of StatsdSender.



10
11
12
13
14
15
# File 'lib/senor_armando/plugins/statsd_plugin.rb', line 10

def initialize options={}
  @name   = options[:name] || File.basename(Goliath::Application.app_file, '.rb')
  @host   = options[:host] || DEFAULT_HOST
  @port   = options[:port] || DEFAULT_PORT
  @logger = options[:logger] || Logger.new
end

Instance Method Details

#count(metric, val = 1, sampling_frac = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/senor_armando/plugins/statsd_plugin.rb', line 21

def count metric, val=1, sampling_frac=nil
  if sampling_frac && (rand < sampling_frac.to_F)
    send_to_statsd "#{name(metric)}:#{val}|c|@#{sampling_frac}"
  else
    send_to_statsd "#{name(metric)}:#{val}|c"
  end
end

#name(metric = []) ⇒ Object



17
18
19
# File 'lib/senor_armando/plugins/statsd_plugin.rb', line 17

def name metric=[]
  [@name, metric].flatten.reject{|x| x.to_s.empty? }.join(".")
end

#timing(metric, val) ⇒ Object



29
30
31
# File 'lib/senor_armando/plugins/statsd_plugin.rb', line 29

def timing metric, val
  send_to_statsd "#{name(metric)}:#{val}|ms"
end