Class: Mongodb::Graphite::Agent::CollectionSizeCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/mongodb/graphite/agent/collection_size_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(mongo_client) ⇒ CollectionSizeCalculator

Returns a new instance of CollectionSizeCalculator.



8
9
10
# File 'lib/mongodb/graphite/agent/collection_size_calculator.rb', line 8

def initialize(mongo_client)
  @mongo_client = mongo_client
end

Instance Method Details

#calculateObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/mongodb/graphite/agent/collection_size_calculator.rb', line 12

def calculate
  collection_count_hash = {}
  @mongo_client.database_names.each { |db_name|
    @mongo_client[db_name].collection_names.each { |collection_name|
      collection_count_hash["collection_sizes.#{db_name}.#{collection_name}"] = @mongo_client[db_name][collection_name].stats()["count"]
    } unless db_name == 'local'
  }
  collection_count_hash["total_documents"] = collection_count_hash.values.inject { |sum,x| sum+x }
  return collection_count_hash
end