Installation
Monit is a great application for monitoring and starting and automatically re-starting applications
sudo apt-get install -y monit
The version installed this way is an old version, NOT the latest stable one
Example configuration for Cassandra
sudo tee /etc/monit/monitrc <<_EOF_ set daemon 10 with start delay 20 # check every 10 seconds, but wait 20 seconds to begin check cassandra matching "cassandra" start program = "/etc/init.d/cassandra start" stop program = "/etc/init.d/cassandra stop" #if failed port 7000 protocol HTTP then restart _EOF_
sudo /etc/init.d/monit status
Manual Installation of Latest Stable Version
mkdir -p ~/build/monit cd ~/build/monit wget http://mmonit.com/monit/dist/monit-latest.tar.gz tar -xvf monit-latest.tar.gz cd monit* ./configure --without-pam make make install #checking for pam_start in -lpam... no #configure: error: PAM enabled but headers or library not found, install the PAM development support or run configure #--without-pam #fix sudo apt-get install -y libpam0g-dev #u libreadline-gplv2-dev
Troubleshooting
> monit summary fails and monit is not started
monit: error connecting to the monit daemon
# add this line to the monitrc confugration files. default location: /etc/monit/monitrc set httpd port 2812 use address 127.0.0.1 # only accept connection from localhost allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
SSL Library not found
... checking for SSL support... enabled checking for SSL include directory... /usr/include checking for SSL library directory... Not found Couldn't find your SSL library files.
Fix: Use --with-ssl-lib-dir option to fix this problem or disable the SSL support with --without-ssl
[monit] monit cannot start scripts: "failed to start"
References 1: http://lists.gnu.org/archive/html/monit-general/2010-06/msg00005.html
References 2: http://old.nabble.com/-monit--monit-cannot-start-scripts%3A-%22failed-to-start%22-td28857673.html
Fix: load your environment, e.g. as follows
program = "/bin/su - user -c '/usr/local/bin/ruby ... ' " start program = "/bin/su - root -c '/etc/init.d/cassandra start'" stop program = "/bin/su - root -c '/etc/init.d/cassandra stop'"
http://stackoverflow.com/questions/3356476/debugging-monit
I've found the most common problems are environment variable related (especially PATH) or permission-related.
The reason is that monit often runs as root.
http://stackoverflow.com/questions/7944344/monit-failing-to-start-process
start program = "/home/user/simple_script_daemon.rb start" as uid user and gid user
m/monit - GUI for Monit
Installation and Start
# create build directory mkdir -p ~/build/mmonit cd ~/build/mmonit # download wget http://mmonit.com/dist/mmonit-2.4-linux-x64.tar.gz tar -xvf mmonit-2.4-linux-x64.tar.gz # move mmonit to /usr/local/share/mmonit cp -r mmonit /usr/local/share/mmonit cd mmonit*/bin sudo ./mmonit
Check Server
URL: http://localhost:8080/
User: admin
Password: swordfish
Stop Server
sudo mmonit stop
References
1. Home: http://mmonit.com/monit/
2. FAQ: http://mmonit.com/wiki/Monit/FAQ
3. Configuration: http://mmonit.com/wiki/Monit/ConfigurationExamples
4. Screenshots: http://mmonit.com/screenshots/
5. Guide: http://www.ubuntugeek.com/monitoring-ubuntu-services-using-monit.html
6. Getting started - Installation: http://mmonit.com/wiki/Monit/Installation
7. http://www.thegeekstuff.com/2010/11/monit-install-config/
8. http://serverfault.com/questions/270316/monit-check-process-without-pidfile
9. http://www.cyberciti.biz/faq/monit-sshd-server-configuration/
10. http://spin.atomicobject.com/2010/11/30/monitoring-and-management-with-monit-and-nagios/
11. http://code.google.com/p/nagios-monit-plugin/
12. http://blog.blindgaenger.net/monitor_applications_with_monit.html
# set daemon 10 with start delay 20
Alternatives
13. Upstart: http://howtonode.org/deploying-node-upstart-monit
14. Upstart: http://upstart.ubuntu.com/
Other Tools
15. Other Tools: http://sixrevisions.com/tools/10-free-server-network-monitoring-tools-that-kick-ass/
16. Nagios: http://www.nagios.org/