|
|
|
@ -28,7 +28,7 @@ class Monitor {
@@ -28,7 +28,7 @@ class Monitor {
|
|
|
|
|
const _self = this; |
|
|
|
|
|
|
|
|
|
if ( !this.config || (typeof(forceReload) != 'undefined' && forceReload) ) { |
|
|
|
|
console.log("Load config from %s", this.configFile); |
|
|
|
|
common.log("Load config from %s", this.configFile); |
|
|
|
|
let config = await common.getConfigFromJsonFile(this.configFile); |
|
|
|
|
|
|
|
|
|
//覆盖默认配置
|
|
|
|
@ -78,12 +78,12 @@ class Monitor {
@@ -78,12 +78,12 @@ class Monitor {
|
|
|
|
|
for (let i=0; i<total; i++) { |
|
|
|
|
if (_self.tasks.find((item) => item.url == configs.monit_urls[i] && item.stats != 'done')) {continue;} |
|
|
|
|
|
|
|
|
|
console.log("Checking url %s ...", configs.monit_urls[i]); |
|
|
|
|
common.log("Checking url %s ...", configs.monit_urls[i]); |
|
|
|
|
taskRes = await common.createHeroUnionTask(configs.monit_urls[i], '', configs); |
|
|
|
|
if (taskRes && taskRes.code == 1) { |
|
|
|
|
_self.tasks.push(taskRes.task); |
|
|
|
|
}else { |
|
|
|
|
console.error("Monit task create failed", taskRes); |
|
|
|
|
common.error("Monit task create failed", taskRes); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, { |
|
|
|
@ -103,14 +103,13 @@ class Monitor {
@@ -103,14 +103,13 @@ class Monitor {
|
|
|
|
|
task = _self.tasks[index]; |
|
|
|
|
if (task.status == 'done') {continue;} |
|
|
|
|
|
|
|
|
|
//console.log('Query task result of %s', task.id);
|
|
|
|
|
taskRes = await common.queryHeroUnionTask(task.id, configs); |
|
|
|
|
if (taskRes && taskRes.code == 1) { |
|
|
|
|
_self.tasks[index] = taskRes.task; //更新任务数据
|
|
|
|
|
|
|
|
|
|
common.log('Task status: %s, url: %s, task id: %s', task.status, task.url, task.id); |
|
|
|
|
common.log('Task status: %s, url: %s, task id: %s', taskRes.task.status, task.url, task.id); |
|
|
|
|
|
|
|
|
|
if (task.status == 'done') { |
|
|
|
|
if (taskRes.task.status == 'done') { |
|
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/ok.log'; |
|
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request success: ${task.url}, task id: ${task.id}\n`); |
|
|
|
@ -120,16 +119,11 @@ class Monitor {
@@ -120,16 +119,11 @@ class Monitor {
|
|
|
|
|
let logData = { |
|
|
|
|
"time": currentTime, |
|
|
|
|
"url": task.url, |
|
|
|
|
"status": task.status |
|
|
|
|
"status": taskRes.task.status |
|
|
|
|
}; |
|
|
|
|
common.saveLog(logFile, JSON.stringify(logData) + `\n`); |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
console.error("Monit task query failed", taskRes); |
|
|
|
|
|
|
|
|
|
common.error('Connect warning, url: %s, task id: %s', task.url, task.id); |
|
|
|
|
|
|
|
|
|
//写入日志
|
|
|
|
|
}else if (taskRes.task.status == 'failed') { |
|
|
|
|
//写入错误日志
|
|
|
|
|
let currentTime = common.getLocalTimeString(); |
|
|
|
|
let logFile = path.resolve(_self.systemLogDir) + '/fail.log'; |
|
|
|
|
common.saveLog(logFile, `[${currentTime}] Url request failed: ${task.url}, task id: ${task.id}\n`); |
|
|
|
@ -143,6 +137,9 @@ class Monitor {
@@ -143,6 +137,9 @@ class Monitor {
|
|
|
|
|
}; |
|
|
|
|
common.saveLog(logFile, JSON.stringify(logData) + `\n`); |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
common.error('Task query failed, url: %s, task id: %s', task.url, task.id, taskRes); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//更新tasks,去掉已完成的
|
|
|
|
|