Node.js:如何在服务器崩溃时收到警告
当我的服务器因任何原因崩溃时,如何收到警告? HopToad 或任何其他服务可以做到这一点吗?
谢谢
编辑:
我正在使用 Heroku 作为 Node.js。这不允许我运行其他任何东西。我需要一些东西来从内到外监视我的代码,而不需要运行任何其他进程。
谢谢
How can I get warned when my server crashes for any reason? Does HopToad or any other service does that?
Thanks
EDIT:
I am using Heroku for node.js. Which doesn't allow me to run anything else. I need something to monit my code from inside out, without needing to run any other process.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试在node.js程序中处理 uncaughtException 事件并在那里做你的“警告我”的事情。或者,您可以使用 uptime robots 之类的服务来监控您的应用程序是否正在侦听指定端口。
You can try to handle uncaughtException event within your node.js program and do your "warn me" stuff there. Or you can use service like uptime robot to monitor if your app is listening on specified port for example.
实际上有相当多的选择!
监控,forever 和 supervisord 在我看来是脱颖而出的。
由于 @rob-cowie 已经回答了有关主管的问题,因此您可以在此处获得一些有关“永远”和“监视”的提示。
Monit 是管理计算机上的服务的整体解决方案 - 当它们崩溃或占用太多资源时通知您并重新启动它们。
我还没有找到一个很好的理由用户supervisord而不是monit,但是在supervisord邮件列表上我看到了使用monit来监视supervisord的建议!
Quite a few options actually!
monit, forever and supervisord are the ones that stick out of the crowd in my opinion.
Since @rob-cowie already answered about supervisor, here you get a few pointer about 'forever' and 'monit'.
Monit is an overall solution to manage services on your machine - notifying you and restarting them when they crash or take up too many resources.
I have yet to find a good reason to user supervisord instead of monit, but on supervisord mailing list I saw suggestions to use monit to monitor supervisord!
我刚刚编写了一个类,用于侦听未处理的异常,当它看到一个异常时:
它需要对您的应用程序进行一些调整,因为我还没有使其通用,但它只有几行,它可能就是您正在寻找的!
它从您的应用程序内部运行,无需包含任何其他文件(如果您想要邮件通知,则nodemailer.js除外..)
检查一下!
I've just put together a class which listens for unhandled exceptions, and when it see's one it:
It will require a little tweaking for your application as I haven't made it generic as yet, but it's only a few lines and it might be what you're looking for!
It runs from inside your app, no need to include any other files (except nodemailer.js if you want the mail notifications..)
Check it out!
一种方法是定期检查您是否可以成功访问您正在服务的页面,请参阅 http://wasitup.com/ 。
另一种方法是监视计算机上的服务器进程。一种好方法是使用 Supervisord 启动 node.js。它可以重新启动崩溃的进程并向您发送电子邮件。 Intarweb 周围有许多示例,包括部署示例1
One approach is to periodically check that you can successfully access a page you are serving, see http://wasitup.com/.
Another approach would be to monitor the server process on your machine. One good way to do this is to launch node.js using Supervisord. It can restart a crashed process and email you. There are numerous examples around the intarwebs, including deployment example1
如果您仍在heroku 上使用node.js,那么Nodejitsu 也值得一看。它对节点有很好的支持,并且永远运行,如果你的应用程序崩溃循环和其他事情,它会发出电子邮件通知。非常方便。
另外,就处理 uncaughtException 而言,我会避免这种情况,从经验来看它是不稳定的,并且在最新的 Node.js api 文档中也指出它是不可靠和不稳定的。请参阅 http://nodejs.org/api/process.html#process_event_uncaughtexception
使用类似的内容永远!
If you're still using node.js on heroku, it's also worth looking at Nodejitsu. It has great support for node and runs forever, with email notifications if your app crash loops and other things. Very handy.
Also, as far as handling
uncaughtException
goes I'd avoid that, from experiences it's unstable and it's also noted in the latest node.js api docs that it's unreliable and unstable. See http://nodejs.org/api/process.html#process_event_uncaughtexceptionUse something like forever!