diff --git a/bin/proxy/master.js b/bin/proxy/master.js index 21003f46..bfbcc09d 100644 --- a/bin/proxy/master.js +++ b/bin/proxy/master.js @@ -14,12 +14,14 @@ const cluster = require('cluster'); const cpuUtil = require('util/cpu.js'); const fs = require('fs'); const serverOS = require('util/isWindows.js'); +const mail = require('util/mail/mail.js'); const { debugOptions } = process.binding('config'); const methodMap = {}; const workerMap = {}; const cpuMap = []; const tnm2 = require('api/tnm2'); const network = require('util/network.js'); +const serverInfo = require('serverInfo.js'); process.on('uncaughtException', function(e) { @@ -262,11 +264,9 @@ function checkWorkerAlive() { // 内存超限进程处理 if (worker.lastMessage) { const currMemory = worker.lastMessage.memoryUsage; - - // logger.debug(currMemory); + const key = `memoryLimit.v1:${serverInfo.intranetIp}`; if (currMemory && currMemory.rss > config.memoryLimit) { - logger.error('worker${cpu} pid=${pid} memoryUsage ${memoryUsage}, hit memoryLimit: ${memoryLimit}, kill it', { memoryUsage: currMemory.rss, memoryLimit: config.memoryLimit, @@ -276,6 +276,15 @@ function checkWorkerAlive() { logger.error(worker.lastMessage); + mail.SendMail(key, 'js', 600, { + 'to': config.mailTo, + 'cc': config.mailCC, + 'runtimeType':'Memory', + 'msgInfo': `${serverInfo.intranetIp} 内存超限,服务已重启。请开发人员关注是否存在内存泄露`, + 'title': `${serverInfo.intranetIp} 内存超限告警`, + 'content': `
${serverInfo.intranetIp} 内存超限,服务已重启。请开发人员关注是否存在内存泄露
` + }); + restartWorker(worker); } } diff --git a/bin/tsw/api/keyman/runtimeType.json b/bin/tsw/api/keyman/runtimeType.json index aa37b7df..7186ce1d 100644 --- a/bin/tsw/api/keyman/runtimeType.json +++ b/bin/tsw/api/keyman/runtimeType.json @@ -8,7 +8,7 @@ "LargeJs" : "内联JS过大", "Js404" : "内联JS不存在", "CPU" : "CPU告警", + "Memory" : "内存超载", "hello" : "hello" - }