Node.js:如何在服务器崩溃时收到警告

发布于 2024-11-07 09:37:06 字数 167 浏览 0 评论 0原文

当我的服务器因任何原因崩溃时,如何收到警告? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃→可爱长大的 2024-11-14 09:37:06

您可以尝试在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.

又爬满兰若 2024-11-14 09:37:06

实际上有相当多的选择!

监控foreversupervisord 在我看来是脱颖而出的。

由于 @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!

时光匆匆的小流年 2024-11-14 09:37:06

我刚刚编写了一个类,用于侦听未处理的异常,当它看到一个异常时:

  • 将堆栈跟踪打印到控制台 将
  • 其记录在它自己的日志
  • 文件中 通过电子邮件将堆栈跟踪
  • 重新启动服务器(或终止它,由您决定) )

它需要对您的应用程序进行一些调整,因为我还没有使其通用,但它只有几行,它可能就是您正在寻找的!

它从您的应用程序内部运行,无需包含任何其他文件(如果您想要邮件通知,则nodemailer.js除外..)

检查一下!

I've just put together a class which listens for unhandled exceptions, and when it see's one it:

  • prints the stack trace to the console
  • logs it in it's own logfile
  • emails you the stack trace
  • restarts the server (or kills it, up to you)

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!

暗藏城府 2024-11-14 09:37:06

一种方法是定期检查您是否可以成功访问您正在服务的页面,请参阅 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

み青杉依旧 2024-11-14 09:37:06

如果您仍在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_uncaughtexception

Use something like forever!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文