Class: OnesnooperServer::Stores::MongodbStore

Inherits:
OnesnooperServer::Store show all
Defined in:
lib/onesnooper_server/stores/mongodb_store.rb

Overview

MongoDB-based store for production deployments and dynamic document structure.

Constant Summary collapse

MONGO_COLL_NAME =

constant collection name

'one_monitoring'

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ MongodbStore


10
11
12
13
14
15
# File 'lib/onesnooper_server/stores/mongodb_store.rb', line 10

def initialize(params = {})
  super
  @db_conn = ::Mongo::MongoClient.new(params[:host], params[:port])
  @db_active_db = @db_conn.db(params[:database])
  @db_coll = @db_active_db.create_collection(MONGO_COLL_NAME)
end

Instance Method Details

#save!(timestamp, data) ⇒ Object


17
18
19
20
21
# File 'lib/onesnooper_server/stores/mongodb_store.rb', line 17

def save!(timestamp, data)
  ::OnesnooperServer::Log.debug "[#{self.class.name}] Saving #{timestamp.to_s} => #{data.inspect}"
  data['TIMESTAMP'] = timestamp.to_time.utc
  @db_coll.insert data
end