Sha256: 40e9cc56c71a29bce21aed945ce478943af6012dc8d415ea26884b4bf3369e51

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

require 'awesome_print'

module Mongodb
  module Graphite
    module Agent
      class CollectionSizeCalculator

        def initialize(mongo_client)
          @mongo_client = mongo_client
        end

        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

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongodb-graphite-agent-0.1.4 lib/mongodb/graphite/agent/collection_size_calculator.rb