|
|
@ -106,22 +106,42 @@ class Monitor { |
|
|
|
//console.log('Query task result of %s', task.id);
|
|
|
|
//console.log('Query task result of %s', task.id);
|
|
|
|
taskRes = await common.queryHeroUnionTask(task.id, configs); |
|
|
|
taskRes = await common.queryHeroUnionTask(task.id, configs); |
|
|
|
if (taskRes && taskRes.code == 1) { |
|
|
|
if (taskRes && taskRes.code == 1) { |
|
|
|
_self.tasks[index] = taskRes.task; |
|
|
|
_self.tasks[index] = taskRes.task; //更新任务数据
|
|
|
|
|
|
|
|
|
|
|
|
common.log('Connect success, url: %s, task id: %s', task.url, task.id); |
|
|
|
common.log('Task status: %s, url: %s, task id: %s', task.status, task.url, task.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (task.status == 'done') { |
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/ok.log'; |
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/ok.log'; |
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request success: ${task.url}, task id: ${task.id}\n`); |
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request success: ${task.url}, task id: ${task.id}\n`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写入JSON格式的log
|
|
|
|
|
|
|
|
logFile = path.resolve(_self.systemLogDir) + '/json_stats.log'; |
|
|
|
|
|
|
|
let logData = { |
|
|
|
|
|
|
|
"time": currentTime, |
|
|
|
|
|
|
|
"url": task.url, |
|
|
|
|
|
|
|
"status": task.status |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
common.saveLog(logFile, JSON.stringify(logData) + `\n`); |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
console.error("Monit task query failed", taskRes); |
|
|
|
console.error("Monit task query failed", taskRes); |
|
|
|
|
|
|
|
|
|
|
|
//TODO: 写入日志,或发送告警
|
|
|
|
|
|
|
|
common.error('Connect warning, url: %s, task id: %s', task.url, task.id); |
|
|
|
common.error('Connect warning, url: %s, task id: %s', task.url, task.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写入日志
|
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/fail.log'; |
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/fail.log'; |
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request failed: ${task.url}, task id: ${task.id}\n`); |
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request failed: ${task.url}, task id: ${task.id}\n`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写入JSON格式的log
|
|
|
|
|
|
|
|
logFile = path.resolve(_self.systemLogDir) + '/json_stats.log'; |
|
|
|
|
|
|
|
let logData = { |
|
|
|
|
|
|
|
"time": currentTime, |
|
|
|
|
|
|
|
"url": task.url, |
|
|
|
|
|
|
|
"status": task.status |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
common.saveLog(logFile, JSON.stringify(logData) + `\n`); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|