class Alephant::Logger::Statsd

Constants

VERSION

Attributes

server[R]

Public Class Methods

new(config = {}) click to toggle source
# File lib/alephant/logger/statsd.rb, line 7
def initialize(config = {})
  @server = connect defaults.merge(config)
end

Public Instance Methods

increment(key, interval = 1) click to toggle source
# File lib/alephant/logger/statsd.rb, line 11
def increment(key, interval = 1)
  send_data { server.increment(key, interval) }
end
Also aliased as: metric
metric(key, interval = 1)
Alias for: increment
timing(key, milliseconds, sample_rate = 1) click to toggle source
# File lib/alephant/logger/statsd.rb, line 17
def timing(key, milliseconds, sample_rate = 1)
  send_data { server.timing(key, milliseconds, sample_rate) }
end

Private Instance Methods

connect(config) click to toggle source
# File lib/alephant/logger/statsd.rb, line 25
def connect(config)
  ::Statsd.new(config[:host], config[:port]).tap do |s|
    s.namespace = config[:namespace]
  end
end
defaults() click to toggle source
# File lib/alephant/logger/statsd.rb, line 31
def defaults
  {
    :host      => "localhost",
    :port      => 8125,
    :namespace => "statsd"
  }
end
send_data() { || ... } click to toggle source
# File lib/alephant/logger/statsd.rb, line 39
def send_data
  Thread.new { yield }
end