Class: Statsd

Inherits:
Object
  • Object
show all
Defined in:
lib/statsd.rb

Overview

Statsd: A Statsd client (github.com/etsy/statsd)

Example:

statsd = Statsd.new 'localhost', 8125

statsd.increment 'garets'
statsd.timing 'glork', 320

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 8125) ⇒ Statsd

Returns a new instance of Statsd.

Parameters:

  • host (String)

    your statsd host

  • port (Integer) (defaults to: 8125)

    your statsd port



16
17
18
# File 'lib/statsd.rb', line 16

def initialize(host, port=8125)
  @host, @port = host, port
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



12
13
14
# File 'lib/statsd.rb', line 12

def namespace
  @namespace
end

Instance Method Details

#count(stat, count, sample_rate = 1) ⇒ Object

Parameters:

  • stat (String)

    stat name

  • count (Integer)

    count

  • sample_rate (Integer) (defaults to: 1)

    sample rate, 1 for always



31
# File 'lib/statsd.rb', line 31

def count(stat, count, sample_rate=1); send stat, count, 'c', sample_rate end

#decrement(stat, sample_rate = 1) ⇒ Object

Parameters:

  • stat (String)

    stat name

  • sample_rate (Integer) (defaults to: 1)

    sample rate, 1 for always



26
# File 'lib/statsd.rb', line 26

def decrement(stat, sample_rate=1); count stat, -1, sample_rate end

#increment(stat, sample_rate = 1) ⇒ Object

Parameters:

  • stat (String)

    stat name

  • sample_rate (Integer) (defaults to: 1)

    sample rate, 1 for always



22
# File 'lib/statsd.rb', line 22

def increment(stat, sample_rate=1); count stat, 1, sample_rate end

#time(stat, sample_rate = 1) ⇒ Object



38
39
40
41
42
43
# File 'lib/statsd.rb', line 38

def time(stat, sample_rate=1)
  start = Time.now
  result = yield
  timing(stat, ((Time.now - start) * 1000).round, sample_rate)
  result
end

#timing(stat, ms, sample_rate = 1) ⇒ Object

Parameters:

  • stat (String)

    stat name

  • ms (Integer)

    timing in milliseconds

  • sample_rate (Integer) (defaults to: 1)

    sample rate, 1 for always



36
# File 'lib/statsd.rb', line 36

def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end