Class: Vmpooler::Metrics::Statsd
- Inherits:
-
Vmpooler::Metrics
- Object
- Vmpooler::Metrics
- Vmpooler::Metrics::Statsd
- Defined in:
- lib/vmpooler/metrics/statsd.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #gauge(label, value) ⇒ Object
- #increment(label) ⇒ Object
-
#initialize(logger, params = {}) ⇒ Statsd
constructor
A new instance of Statsd.
- #timing(label, duration) ⇒ Object
Methods inherited from Vmpooler::Metrics
Constructor Details
#initialize(logger, params = {}) ⇒ Statsd
Returns a new instance of Statsd.
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
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/vmpooler/metrics/statsd.rb', line 9 def port @port end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/vmpooler/metrics/statsd.rb', line 9 def prefix @prefix end |
#server ⇒ Object (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 |