Class: MongodbGraphite::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/mongodb-graphite/instance.rb

Constant Summary collapse

OPTIONS =
[:host, :port, :prefix_callback, :fields_to_ignore]

Instance Method Summary collapse

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)
  OPTIONS.each do |opt|
    val = instance_variable_get "@#{opt}"
    if options[opt] != val and not options[opt].nil?
      instance_variable_set "@#{opt}", options.delete(opt)
    end
  end
end

#to_graphiteObject



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_sObject



41
42
43
# File 'lib/mongodb-graphite/instance.rb', line 41

def to_s
  "#{@name} #{@host}:#{@port}, #{@prefix_callback.class}"
end