Class: MongodbGraphite::Instance
- Inherits:
-
Object
- Object
- MongodbGraphite::Instance
- Defined in:
- lib/mongodb-graphite/instance.rb
Constant Summary collapse
- OPTIONS =
[:host, :port, :prefix_callback, :fields_to_ignore]
Instance Method Summary collapse
-
#initialize(name) ⇒ Instance
constructor
A new instance of Instance.
- #reload(options) ⇒ Object
- #to_graphite ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Instance
Returns a new instance of Instance.
17 18 19 20 21 22 23 24 |
# File 'lib/mongodb-graphite/instance.rb', line 17 def initialize(name) @name = name @port = 27017 @host = 'localhost' @fields_to_ignore = %w(host version process pid uptimeMillis localTime extra_info.note backgroundFlushing.last_finished repl.setName repl.hosts repl.arbiters repl.primary repl.me ok) @prefix_callback = nil @replacements = { /locks\.\.\./ => 'locks.global.' } end |
Instance Method Details
#reload(options) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/mongodb-graphite/instance.rb', line 26 def reload() OPTIONS.each do |opt| val = instance_variable_get "@#{opt}" if [opt] != val and not [opt].nil? instance_variable_set "@#{opt}", .delete(opt) end end end |
#to_graphite ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/mongodb-graphite/instance.rb', line 45 def to_graphite @stats = to_hash with_prefix = Hash.new @stats.each do |k,v| key = format_key k with_prefix[ [prefix, key].join('.')] = to_i(v) end with_prefix.reject { |k,v| ignored_fields.include? k } end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/mongodb-graphite/instance.rb', line 41 def to_s "#{@name} #{@host}:#{@port}, #{@prefix_callback.class}" end |