Skip to content
Snippets Groups Projects
Commit ea8ab9fe authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Slight update to logging in aggregator

parent c40efc7d
No related branches found
No related tags found
No related merge requests found
......@@ -32,14 +32,6 @@ import sys
import logging
log = logging.getLogger('aggregator')
hdlr = logging.FileHandler('/var/log/clmcservice/aggregator.log', mode='a')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
log.addHandler(hdlr)
log.setLevel(logging.INFO)
class Aggregator(object):
"""
A class used to perform the aggregation feature of the CLMC - aggregating network and media service measurements. Implemented as a separate process.
......@@ -49,7 +41,7 @@ class Aggregator(object):
DATABASE = 'CLMCMetrics' # default database the aggregator uses
DATABASE_URL = 'http://172.40.231.51:8086' # default database URL the aggregator uses
def __init__(self, database_name=DATABASE, database_url=DATABASE_URL, report_period=REPORT_PERIOD):
def __init__(self, database_name=DATABASE, database_url=DATABASE_URL, report_period=REPORT_PERIOD, logger=None):
"""
Constructs an Aggregator instance.
......@@ -58,11 +50,16 @@ class Aggregator(object):
:param report_period: the report period in seconds
"""
log.info("Connecting to Influx database {0} with URL {1}".format(database_name, database_url))
if logger is None:
self.log = logging.getLogger('aggregator')
else:
self.log = logger
self.log.info("Connecting to Influx database {0} with URL {1}".format(database_name, database_url))
# initialise a database client using the database url and the database name
url_object = urlparse(database_url)
self.db_client = InfluxDBClient(host=url_object.hostname, port=url_object.port, database=database_name, timeout=10)
log.info("Successfully connected to Influx database {0} with URL {1}".format(database_name, database_url))
self.log.info("Successfully connected to Influx database {0} with URL {1}".format(database_name, database_url))
self.db_url = database_url
self.db_name = database_name
......@@ -80,7 +77,7 @@ class Aggregator(object):
Stop the aggregator from running.
"""
log.info("Aggregator's stop flag has been set.")
self.log.info("Aggregator's stop flag has been set.")
self._stop_flag.set()
def run(self):
......@@ -88,11 +85,11 @@ class Aggregator(object):
Performs the functionality of the aggregator - query data from both measurements merge that data and post it back in influx every 5 seconds.
"""
log.info("Aggregator started running.")
self.log.info("Aggregator started running.")
current_time = int(time())
while not self._stop_flag.is_set():
log.info("Trying to generate an E2E measurement.")
self.log.info("Trying to generate an E2E measurement.")
boundary_time = current_time - self.report_period
......@@ -171,9 +168,9 @@ class Aggregator(object):
e2e_arguments['delay_service'],
e2e_arguments["avg_request_size"], e2e_arguments['avg_response_size'], e2e_arguments['avg_bandwidth'],
e2e_arguments['time']))
log.info("Successfully generated an E2E measurement and posted back to Influx.")
self.log.info("Successfully generated an E2E measurement and posted back to Influx.")
else:
log.info("Couldn't generate an E2E measurement although some of the data could be fetched.")
self.log.info("Couldn't generate an E2E measurement although some of the data could be fetched.")
old_timestamp = current_time
# wait until {report_period) seconds have passed
......@@ -181,10 +178,16 @@ class Aggregator(object):
sleep(1)
current_time = int(time())
log.info("Aggregator stopped running.")
self.log.info("Aggregator stopped running.")
if __name__ == '__main__':
log = logging.getLogger('aggregator')
hdlr = logging.FileHandler('/var/log/clmcservice/aggregator.log', mode='a')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
log.addHandler(hdlr)
log.setLevel(logging.INFO)
# Parse command line options
try:
......@@ -203,7 +206,7 @@ if __name__ == '__main__':
elif opt in ('-u', '--url'):
arg_database_url = arg
Aggregator(database_name=arg_database_name, database_url=arg_database_url, report_period=arg_period).run()
Aggregator(database_name=arg_database_name, database_url=arg_database_url, report_period=arg_period, logger=log).run()
# log.info the error messages in case of a parse error
except getopt.GetoptError as err:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment