最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js: How To Get Warned When Server Crashes - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question edited May 12, 2011 at 8:43 Donald asked May 12, 2011 at 8:13 DonaldDonald 2331 gold badge4 silver badges10 bronze badges 1
  • Hey not sure if you still using this setup or have an insight on what to use - do you remend any of the add ons like pingdom/stillalive/new relic? – Lion789 Commented May 22, 2016 at 22:24
Add a ment  | 

5 Answers 5

Reset to default 9

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.

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.

  • Full exemple of Forever with nodejs
  • nodejs with updstart and monit (from somebody who was using forever before)

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!

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!

One approach is to periodically check that you can successfully access a page you are serving, see http://wasitup./.

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

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/api/process.html#process_event_uncaughtexception

Use something like forever!

发布评论

评论列表(0)

  1. 暂无评论