From c1ae1a9b19e7eba0e03de4973b5bc3a4ec39f7c4 Mon Sep 17 00:00:00 2001 From: Evgeny Smyshlyaev Date: Thu, 25 Oct 2018 20:35:19 +0300 Subject: [PATCH] Server logs improvements #48 (#205) improve logs --- analytics/server.py | 2 +- .../src/controllers/analytics_controller.ts | 5 +++++ server/src/services/analytics_service.ts | 20 +++++++++---------- server/src/services/data_service.ts | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/analytics/server.py b/analytics/server.py index 2b49700..a5d150a 100644 --- a/analytics/server.py +++ b/analytics/server.py @@ -19,7 +19,7 @@ data_service: services.DataService = None root.setLevel(logging.DEBUG) -logging_formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s") +logging_formatter = logging.Formatter("%(asctime)s [Analytics] [%(levelname)-5.5s] %(message)s") logging_handler = logging.StreamHandler(sys.stdout) #logging_handler = logging.FileHandler(config.DATA_FOLDER + '/analytics.log') diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index be7befa..7eb4564 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -92,6 +92,7 @@ function getQueryRangeForLearningBySegments(segments: Segment.Segment[]) { } export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { + console.debug('learning runned...'); try { let analyticUnit = await AnalyticUnit.findById(id); @@ -107,6 +108,7 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { let segmentObjs = segments.map(s => s.toObject()); let { from, to } = getQueryRangeForLearningBySegments(segments); + console.debug(`query metrics from ${analyticUnit.panelUrl}`); let queryResult = await queryByMetric(analyticUnit.metric, analyticUnit.panelUrl, from, to, HASTIC_API_KEY); let data = queryResult.values; if(data.length === 0) { @@ -129,6 +131,7 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { id, AnalyticsTaskType.LEARN, { pattern, segments: segmentObjs, data, cache: oldCache } ); AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.LEARNING); + console.debug(`run task, id:${id}`); let result = await runTask(task); if(result.status !== AnalyticUnit.AnalyticUnitStatus.SUCCESS) { throw new Error(result.error) @@ -155,6 +158,7 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { } let { from, to } = getQueryRangeForLearningBySegments(segments); + console.debug(`query metrics from ${unit.panelUrl}`); let queryResult = await queryByMetric(unit.metric, unit.panelUrl, from, to, HASTIC_API_KEY); let data = queryResult.values; if(data.length === 0) { @@ -172,6 +176,7 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { AnalyticsTaskType.PREDICT, { pattern, lastPredictionTime: unit.lastPredictionTime, data, cache: oldCache } ); + console.debug(`run task, id:${id}`); let result = await runTask(task); if(result.status === AnalyticUnit.AnalyticUnitStatus.FAILED) { return []; diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 3cc920a..4fd8f2a 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -47,6 +47,7 @@ export class AnalyticsService { return new Promise((resolve, reject) => { this._requester.send(text, undefined, (err: any) => { if(err) { + console.trace(`got error while sending ${err}`); reject(err); } else { resolve(); @@ -64,7 +65,7 @@ export class AnalyticsService { fs.unlinkSync(this._ipcPath); } this._requester.close(); - console.log('Ok'); + console.log('Terminating successful'); } public get ready(): boolean { return this._ready; } @@ -81,7 +82,7 @@ export class AnalyticsService { console.log("Binding to zmq... %s", this._zmqConnectionString); this._requester.connect(this._zmqConnectionString); this._requester.on("message", this._onAnalyticsMessage.bind(this)); - console.log('Ok'); + console.log('Binding successful'); if(this._productionMode && !this._inDocker) { console.log('Creating analytics process...'); @@ -91,12 +92,12 @@ export class AnalyticsService { console.error('Can`t run analytics process: %s', error); return; } - console.log('Ok, pid: %s', cp.pid); + console.log('Analytics creating successful, pid: %s', cp.pid); } console.log('Start analytics pinger...'); this._runAlalyticsPinger(); - console.log('Ok'); + console.log('Analytics pinger started'); } @@ -136,24 +137,23 @@ export class AnalyticsService { return new Promise((resolve, reject) => { var resolved = false; - cp.stdout.on('data', () => { + cp.stdout.on('data', (data) => { + console.log(data); if(resolved) { return; - } else { - resolved = true; } + resolved = true; resolve(cp); }); cp.stderr.on('data', function(data) { + console.error(data); if(resolved) { return; - } else { - resolved = true; } + resolved = true; reject(data); }); - }); } diff --git a/server/src/services/data_service.ts b/server/src/services/data_service.ts index 51ee14a..a0faab2 100644 --- a/server/src/services/data_service.ts +++ b/server/src/services/data_service.ts @@ -195,7 +195,7 @@ function maybeCreateDir(path: string): void { if(fs.existsSync(path)) { return; } - console.log('mkdir: ' + path); + console.log('data service: mkdir: ' + path); fs.mkdirSync(path); }