Class: Vmpooler::Statsd
- Inherits:
-
Object
- Object
- Vmpooler::Statsd
- Defined in:
- lib/vmpooler/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(params = {}) ⇒ Statsd
constructor
A new instance of Statsd.
- #timing(label, duration) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Statsd
Returns a new instance of Statsd.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vmpooler/statsd.rb', line 8 def initialize(params = {}) if params['server'].nil? || params['server'].empty? raise ArgumentError, "Statsd server is required. Config: #{params.inspect}" end host = params['server'] @port = params['port'] || 8125 @prefix = params['prefix'] || 'vmpooler' @server = ::Statsd.new(host, @port) end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/vmpooler/statsd.rb', line 6 def port @port end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/vmpooler/statsd.rb', line 6 def prefix @prefix end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/vmpooler/statsd.rb', line 6 def server @server end |
Instance Method Details
#gauge(label, value) ⇒ Object
25 26 27 28 29 |
# File 'lib/vmpooler/statsd.rb', line 25 def gauge(label, value) server.gauge(prefix + '.' + label, value) rescue => err $stderr.puts "Failure updating gauge #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}" end |
#increment(label) ⇒ Object
19 20 21 22 23 |
# File 'lib/vmpooler/statsd.rb', line 19 def increment(label) server.increment(prefix + '.' + label) rescue => err $stderr.puts "Failure incrementing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}" end |
#timing(label, duration) ⇒ Object
31 32 33 34 35 |
# File 'lib/vmpooler/statsd.rb', line 31 def timing(label, duration) server.timing(prefix + '.' + label, duration) rescue => err $stderr.puts "Failure updating timing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}" end |