Bal*_*nam 5 node.js express pm2
我正在运行一个快速应用程序,并且正在使用PM2使其保持活动状态,并在系统中出现任何错误时重新启动。PM2记录错误并重新启动,这非常好。但是我需要用错误消息通知提交此信息的用户。重新启动发生时或将错误写入日志文件时,是否有任何激活的方式,事件或触发器,以便我可以尝试捕获并通知实际用户?
我按照以下建议实施了
var pm2 = require('pm2');
pm2.connect(function(err) {
if (err) {
console.error(err);
process.exit(2);
}
console.log("connected to pm2")
pm2.launchBus(function(err, bus) {
bus.on('log:err', function(e) {
// Send emails
console.log("error in pm2 send email");
});
});
});
Run Code Online (Sandbox Code Playgroud)
我可以在output.log中看到“已连接到pm2”,但在任何地方都看不到“在pm2中发送电子邮件时出错”。但是我看到一个错误日志,我正在触发该错误日志以强制在error.log中出现错误情况。
1) 您可以使用Keymetrics的警报系统
2) 您可以连接到 pm2 总线并捕获错误:
// alerts.js
var pm2 = require('pm2')
pm2.launchBus(function(err, bus) {
bus.on('log:err', function(e) {
// Send emails
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2530 次 |
| 最近记录: |