Class: Vmpooler::Metrics::Statsd

Inherits:
Vmpooler::Metrics show all
Defined in:
lib/vmpooler/metrics/statsd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Vmpooler::Metrics

init

Constructor Details

#initialize(logger, params = {}) ⇒ Statsd

Returns a new instance of Statsd.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/vmpooler/metrics/statsd.rb', line 11

def initialize(logger, params = {})
  raise ArgumentError, "Statsd server is required. Config: #{params.inspect}" if params['server'].nil? || params['server'].empty?

  host    = params['server']
  @port   = params['port'] || 8125
  @prefix = params['prefix'] || 'vmpooler'
  @server = ::Statsd.new(host, @port)
  @logger = logger
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/vmpooler/metrics/statsd.rb', line 9

def port
  @port
end

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/vmpooler/metrics/statsd.rb', line 9

def prefix
  @prefix
end

#serverObject (readonly)

Returns the value of attribute server.



9
10
11
# File 'lib/vmpooler/metrics/statsd.rb', line 9

def server
  @server
end

Instance Method Details

#gauge(label, value) ⇒ Object



27
28
29
30
31
# File 'lib/vmpooler/metrics/statsd.rb', line 27

def gauge(label, value)
  server.gauge(prefix + '.' + label, value)
rescue StandardError => e
  @logger.log('s', "[!] Failure updating gauge #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}")
end

#increment(label) ⇒ Object



21
22
23
24
25
# File 'lib/vmpooler/metrics/statsd.rb', line 21

def increment(label)
  server.increment(prefix + '.' + label)
rescue StandardError => e
  @logger.log('s', "[!] Failure incrementing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}")
end

#timing(label, duration) ⇒ Object



33
34
35
36
37
# File 'lib/vmpooler/metrics/statsd.rb', line 33

def timing(label, duration)
  server.timing(prefix + '.' + label, duration)
rescue StandardError => e
  @logger.log('s', "[!] Failure updating timing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{e}")
end