lib/simple_metrics/mongo.rb in simple_metrics-0.0.1 vs lib/simple_metrics/mongo.rb in simple_metrics-0.2.2

- old
+ new

@@ -10,10 +10,11 @@ Bucket.all.each do |bucket| unless db.collection_names.include?(bucket.name) db.create_collection(bucket.name, :capped => bucket.capped, :size => bucket.size) SimpleMetrics.logger.debug "SERVER: MongoDB - created collection #{bucket.name}, capped: #{bucket.capped}, size: #{bucket.size}" end + db.collection(bucket.name).ensure_index([['ts', ::Mongo::ASCENDING]]) SimpleMetrics.logger.debug "SERVER: MongoDB - ensure index on column ts for collection #{bucket.name}" end end @@ -34,10 +35,10 @@ def collection(name) @@collection[name] ||= db.collection(name) end def connection - @@connection ||= ::Mongo::Connection.new(SimpleMetrics.db_config[:host]) + @@connection ||= ::Mongo::Connection.new(SimpleMetrics.db_config[:host], SimpleMetrics.db_config[:port]) end def db @@db ||= connection.db(SimpleMetrics.db_config[:db_name], SimpleMetrics.db_config[:options]) end