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

rubocop:disable Lint/MissingSuper

Raises:

  • (ArgumentError)


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

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



29
30
31
32
33
# File 'lib/vmpooler/metrics/statsd.rb', line 29

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

rubocop:enable Lint/MissingSuper



23
24
25
26
27
# File 'lib/vmpooler/metrics/statsd.rb', line 23

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



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

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