Class: Statsd::Client

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

Overview

Statsd::Client by Ben VandenBos github.com/bvandenbos/statsd-client

Constant Summary collapse

Version =
'0.0.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost', port = 8125) ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#decrement(stats, sample_rate = 1) ⇒ Object

stats can be a string or an array of strings



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

def decrement(stats, sample_rate = 1)
  update_counter stats, -1, sample_rate
end

#increment(stats, sample_rate = 1) ⇒ Object

stats can be a string or an array of strings



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

def increment(stats, sample_rate = 1)
  update_counter stats, 1, sample_rate
end

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

stat to log timing for time is the time to log in ms



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

def timing(stat, time, sample_rate = 1)
  send_stats "#{stat}:#{time}|ms", sample_rate
end

#update_counter(stats, delta = 1, sample_rate = 1) ⇒ Object

stats can be a string or array of strings



35
36
37
38
# File 'lib/statsd.rb', line 35

def update_counter(stats, delta = 1, sample_rate = 1)
  stats = Array(stats)
  send_stats(stats.map { |s| "#{s}:#{delta}|c" }, sample_rate)
end