Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
true
&& (nowDate.getHours() % 8 === 0)
&& nowDate.getMinutes() === 1
&& nowDate.getSeconds() <= 10
) {
// 8小时一次
require('api/keyman/runtimeAdd.js').hello();
}
// after 1 minute
if (checkWorkerAliveCount % 12 === 0) {
const info = network.getNetInfo();
// network report
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);
// cpu load report
cpuUtil.getCpuLoadAsync().then(function(data) {
if (!data) {
return;
}
};
freqCache.detail[mod_act] = cfg;
}
cfg.count++;
// 最后一条报错信息也记录下来
// cfg.errMsg = merge(str, obj);
// 总错误量超过了上限
if (freqCache.count > errFreqConfig.count) {
exceed = true;
logger && logger.drop();
tnm2.Attr_API('SUM_TSW_ERROR_LOG_DROP', 1);
}
return exceed;
}
if (checkWorkerAliveCount % 12 === 0) {
const info = network.getNetInfo();
// network report
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);
// cpu load report
cpuUtil.getCpuLoadAsync().then(function(data) {
if (!data) {
return;
}
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_1', data.L1);
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_5', data.L5);
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_15', data.L15);
});
}
tnm2.Attr_API_Set('AVG_TSW_CPU_USED', global.cpuUsed);
}, checkWorkerAliveTimeout);
}
// after 1 minute
if (checkWorkerAliveCount % 12 === 0) {
const info = network.getNetInfo();
// network report
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXBIT', info.external.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_RXPCK', info.external.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXBIT', info.external.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_EXTERNAL_TXPCK', info.external.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXBIT', info.internal.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_RXPCK', info.internal.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXBIT', info.internal.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_INTERNAL_TXPCK', info.internal.transmit.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXBIT', info.local.receive.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_RXPCK', info.local.receive.packets);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXBIT', info.local.transmit.bytes);
tnm2.Attr_API('SUM_TSW_NET_LOCAL_TXPCK', info.local.transmit.packets);
// cpu load report
cpuUtil.getCpuLoadAsync().then(function(data) {
if (!data) {
return;
}
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_1', data.L1);
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_5', data.L5);
tnm2.Attr_API_Set('AVG_TSW_CPU_LOAD_15', data.L15);
});
}
tnm2.Attr_API_Set('AVG_TSW_CPU_USED', global.cpuUsed);
}, checkWorkerAliveTimeout);
process.on('reload', function(GET) {
logger.info('reload event fired.');
tnm2.Attr_API('SUM_TSW_WORKER_RELOAD', 1);
for (const key in workerMap) {
const worker = workerMap[key];
const cpu = getToBindCpu(worker);
let timeout = 1000;
if (config.isTest || config.devMode) {
timeout = (cpu % 8) * 1000;
} else {
timeout = (cpu % 8) * 3000;
}
setTimeout((function(worker, cpu) {
return function() {
restartWorker(worker);
};
RoundRobinHandle.prototype.distribute = function(err, handle) {
if (cpuUsed !== global.cpuUsed) {
if (global.cpuUsed > cpuLimit) {
rejectRate = rejectRate + 0.2 * ((global.cpuUsed - cpuLimit) / 100);
} else {
rejectRate = rejectRate + 0.1 * ((global.cpuUsed - cpuLimit) / 100);
}
cpuUsed = global.cpuUsed;
}
if (rejectRate > 0 && Math.random() < rejectRate) {
handle.close();
tnm2.Attr_API('SUM_TSW_OVERLOAD_REJECT', 1);
return;
}
distribute.call(this, err, handle);
};
distribute.hasHack = true;
tnm2.Attr_API('SUM_TSW_HTTP_302', 1);
} else if (res.statusCode === 304) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_304', 1);
} else if (res.statusCode === 403) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_403', 1);
} else if (res.statusCode === 404) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_404', 1);
} else if (res.statusCode === 418) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_418', 1);
} else if (res.statusCode === 419) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_419', 1);
} else if (res.statusCode === 666) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_666', 1);
} else if (res.statusCode === 501) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_501', 1);
} else if (res.statusCode === 508) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_508', 1);
} else if (res.statusCode >= 500 && res.statusCode <= 599) {
isFail = 1;
tnm2.Attr_API('SUM_TSW_HTTP_500', 1);
} else {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_OTHER', 1);
}
tnm2.Attr_API('SUM_TSW_HTTP_418', 1);
} else if (res.statusCode === 419) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_419', 1);
} else if (res.statusCode === 666) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_666', 1);
} else if (res.statusCode === 501) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_501', 1);
} else if (res.statusCode === 508) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_508', 1);
} else if (res.statusCode >= 500 && res.statusCode <= 599) {
isFail = 1;
tnm2.Attr_API('SUM_TSW_HTTP_500', 1);
} else {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_OTHER', 1);
}
req.timestamps.ServerBeginResponse = req.timestamps.ServerBeginResponse || now;
req.timestamps.GotResponseHeaders = req.timestamps.ServerBeginResponse;
req.timestamps.ServerDoneResponse = res.ServerDoneResponse || now;
req.timestamps.ClientBeginResponse = req.timestamps.ServerBeginResponse;
req.timestamps.ClientDoneResponse = req.timestamps.ServerDoneResponse;
logger.debug('finish, statusCode: ${statusCode},cost: ${cost}ms', {
statusCode: res.statusCode,
cost: Date.now() - start.getTime()
});
defer.always(function(){
tnm2.Attr_API('SUM_TSW_CD_CHECK', 1);
});
tnm2.Attr_API('SUM_TSW_HTTP_302', 1);
} else if (res.statusCode === 303) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_302', 1);
} else if (res.statusCode === 307) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_302', 1);
} else if (res.statusCode === 304) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_304', 1);
} else if (res.statusCode === 403) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_403', 1);
} else if (res.statusCode === 404) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_404', 1);
} else if (res.statusCode === 418) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_418', 1);
} else if (res.statusCode === 419) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_419', 1);
} else if (res.statusCode === 666) {
isFail = 0;
tnm2.Attr_API('SUM_TSW_HTTP_666', 1);
} else if (res.statusCode === 501) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_501', 1);
} else if (res.statusCode === 508) {
isFail = 2;
tnm2.Attr_API('SUM_TSW_HTTP_508', 1);
} else if (res.statusCode >= 500 && res.statusCode <= 599) {