Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: How To Get Warned When Server Crashes

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

like image 386
Donald Avatar asked May 12 '11 08:05

Donald


People also ask

Is .NET harder than node?

NET Core has an easier time working with CPU-intensive tasks and rendering static pages since the in-built IIS server kernel caching makes this process very straightforward. Therefore, . NET core vs node. js performance offers different advantages for various projects.

How do I check nodeJS server status?

uptime() will return the time from where the server is started. Thus, you can run the URL like 192.168. 10.10:3000/status (or with public IP) to check if the server is running node or not.


3 Answers

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.

like image 188
yojimbo87 Avatar answered Sep 23 '22 14:09

yojimbo87


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!

like image 41
Stefano Avatar answered Sep 19 '22 14:09

Stefano


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

like image 25
Rob Cowie Avatar answered Sep 20 '22 14:09

Rob Cowie