Skip to content

Commit

Permalink
chore(runtime): add Memory over load alert
Browse files Browse the repository at this point in the history
  • Loading branch information
bdliu(刘彬德) committed Jul 16, 2018
1 parent 7e5d4e9 commit e559153
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions bin/proxy/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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,
Expand All @@ -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': `<p><strong>${serverInfo.intranetIp} 内存超限,服务已重启。请开发人员关注是否存在内存泄露</strong></p>`
});

restartWorker(worker);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/tsw/api/keyman/runtimeType.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"LargeJs" : "内联JS过大",
"Js404" : "内联JS不存在",
"CPU" : "CPU告警",
"Memory" : "内存超载",
"hello" : "hello"

}

0 comments on commit e559153

Please sign in to comment.