Browse Source

Server logs improvements #48 (#205)

improve logs
pull/1/head
Evgeny Smyshlyaev 6 years ago committed by GitHub
parent
commit
c1ae1a9b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      analytics/server.py
  2. 5
      server/src/controllers/analytics_controller.ts
  3. 20
      server/src/services/analytics_service.ts
  4. 2
      server/src/services/data_service.ts

2
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')

5
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 [];

20
server/src/services/analytics_service.ts

@ -47,6 +47,7 @@ export class AnalyticsService {
return new Promise<void>((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<childProcess.ChildProcess>((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);
});
});
}

2
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);
}

Loading…
Cancel
Save