Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for connection to remote mongodb #23

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions mnemosyne.cfg.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ host = 0.0.0.0
port = 8181

[mongodb]
host = 127.0.0.1
port = 27017
database = mnemosyne

[hpfriends]
Expand Down
6 changes: 3 additions & 3 deletions persistance/mnemodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@


class MnemoDB(object):
def __init__(self, database_name):
def __init__(self, mongo_host, mongo_port, database_name):
logger.info('Connecting to mongodb, using "{0}" as database.'.format(database_name))
conn = MongoClient(auto_start_request=False)
self.rg = ReportGenerator(database_name)
conn = MongoClient(host=mongo_host, port=mongo_port, auto_start_request=False)
self.rg = ReportGenerator(mongo_host, mongo_port, database_name)
self.db = conn[database_name]
self.ensure_index()

Expand Down
4 changes: 2 additions & 2 deletions persistance/preagg_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ReportGenerator:
Generates pre-aggregated reports.
"""

def __init__(self, database_name):
def __init__(self, mongo_host, mongo_port, database_name):
logger.info('Connecting to mongodb, using "{0}" as database.'.format(database_name))
conn = MongoClient(w=0)
conn = MongoClient(host=mongo_host, port=mongo_port, w=0)
self.db = conn[database_name]

def hpfeeds(self, entry):
Expand Down
4 changes: 3 additions & 1 deletion runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def parse_config(config_file):
config['loggly_token'] = parser.get('loggly_log', 'token')

config['mongo_db'] = parser.get('mongodb', 'database')
config['mongo_host'] = parser.get('mongodb', 'host')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have default values so people could still use the old mnemosyne config.

config['mongo_port'] = parser.get('mongodb', 'port')

config['hpf_feeds'] = parser.get('hpfriends', 'channels').split(',')
config['hpf_ident'] = parser.get('hpfriends', 'ident')
Expand Down Expand Up @@ -113,7 +115,7 @@ def do_logging(file_log=None, loggly_token=None):

greenlets = {}

db = mnemodb.MnemoDB(c['mongo_db'])
db = mnemodb.MnemoDB(c['mongo_host'], c['mongo_port'], c['mongo_db'])

webapi = None
hpfriends_puller = None
Expand Down