Class: Statsd

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

Constant Summary collapse

Version =
'0.0.8'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hostObject

Returns the value of attribute host.



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

def host
  @host
end

.portObject

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.decrement(stats, sample_rate = 1) ⇒ Object

stats can be a string or an array of strings



42
43
44
# File 'lib/statsd.rb', line 42

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

.gauge(stat, value, sample_rate = 1) ⇒ Object



32
33
34
# File 'lib/statsd.rb', line 32

def gauge(stat, value, sample_rate = 1)
  send_stats("#{stat}:#{value}|g", sample_rate)
end

.host_ip_addrObject



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

def host_ip_addr
  @host_ip_addr ||= Resolv.getaddress(host)
end

.increment(stats, sample_rate = 1) ⇒ Object

stats can be a string or an array of strings



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

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

.timing(stat, time = nil, sample_rate = 1) ⇒ Object

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



23
24
25
26
27
28
29
30
# File 'lib/statsd.rb', line 23

def timing(stat, time = nil, sample_rate = 1)
  if block_given?
    start_time = Time.now.to_f
    yield
    time = ((Time.now.to_f - start_time) * 1000).floor
  end
  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



47
48
49
50
# File 'lib/statsd.rb', line 47

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