Class: Statsd

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

Defined Under Namespace

Classes: Client, DummyClient

Class Method Summary collapse

Class Method Details

.clientObject



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

def client
  return Statsd::DummyClient if deactivated?
  @client ||= Statsd::Client.new(host, port, tcp?)
end

.configObject



41
42
43
44
45
46
47
48
# File 'lib/statsd/client.rb', line 41

def config
  home = File.expand_path('~')
  files = ["#{home}/.statsd-client.yml", '/etc/statsd-client.yml']
  files.each do |file|
    return YAML.load(File.read(file)) if File.exist?(file)
  end
  raise "No config found: #{files.join(' or ')}"
end

.deactivated?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/statsd/client.rb', line 67

def deactivated?
  config['deactivated'] || false
end

.decrement(metric, options = {}) ⇒ Object Also known as: dec



19
20
21
22
23
24
25
26
27
28
# File 'lib/statsd/client.rb', line 19

def decrement(metric, options={})
  if options.is_a?(Fixnum)
    value = options
    sample_rate = 1
  else
    value = (options[:by] || 1)
    sample_rate = (options[:sample_rate] || 1)
  end
  client.update_stats(metric, value*factor*(-1), sample_rate)
end

.factorObject

statds reports with default configs 1/10 of actual value



63
64
65
# File 'lib/statsd/client.rb', line 63

def factor
  config['factor'] || 1
end

.hostObject



50
51
52
# File 'lib/statsd/client.rb', line 50

def host
  config['host'] || 'localhost'
end

.increment(metric, options = {}) ⇒ Object Also known as: inc



7
8
9
10
11
12
13
14
15
16
# File 'lib/statsd/client.rb', line 7

def increment(metric, options={})
  if options.is_a?(Fixnum)
    value = options
    sample_rate = 1
  else
    value = (options[:by] || 1)
    sample_rate = (options[:sample_rate] || 1)
  end
  client.update_stats(metric, value*factor, sample_rate)
end

.portObject



54
55
56
# File 'lib/statsd/client.rb', line 54

def port
  config['port'] || 8125
end

.tcp?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/statsd/client.rb', line 58

def tcp?
  config['tcp']
end

.timing(metric, value) ⇒ Object Also known as: time



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

def timing(metric, value)
  client.timing(metric, value)
end