#375 Monit pro
Aug 16, 2012 | 16 minutes | Tools, Deployment, Production
Monit can help ensure your Rails app stays up and running smoothly. Here I show how to set it up, receive alerts, and keep tabs on it through a web interface.
- source codeProject Files in Zip (79 KB)
- mp4Full Size H.264 Video (43.2 MB)
- m4vSmaller H.264 Video (20.4 MB)
- webmFull Size VP8 Video (23.5 MB)
- ogvFull Size Theora Video (50.4 MB)
I made a Heroku Buildpack for Monit: https://github.com/k33l0r/monit-buildpack
Of course Heroku limits what you can do with it, but at the very least you can use it to monitor your sites and external services…
Monit is cool, but Ubuntu already provide similar monitor features via UpStart and other Linux distro are switching to systemd.
What do you think about the foreman approch, that can be used on heroku and standalone? http://grigio.org/dns_setup_and_procfile_local_development_and_deployment?rc
Foreman already export the ""keep-alive script" towards monit or upstart http://ddollar.github.com/foreman/#UPSTART-EXPORT
Using Foreman with Upstart is the way to go these days. This is a decent post on it.
Foreman has a major flaw that makes it a non-starter for me: it can't handle different commands for starting and stopping a service. It also doesn't allow for different environments without using a wrapper shell script.
Guys, I ran into an issue with Monit + Resque + rbenv setup. My Resque workers fail to start with Monit saying
rbenv: not found, but the same command works fine if I run it directly in console under user deployer. Have someone managed to set up monit to monitor Resque workers? Any ideas?
I've posted some more info here: http://stackoverflow.com/questions/12094311/managing-resque-workers-with-monit-on-rbenv-setup
Two things to make sure:
Hope that helps.
Oh, also su to your "deployer" user and run the magical "rbenv rehash" command? Dunno, just a thought.
Hi, monit doesn't want to monitor workers, that's very strange, my app is working and if I do ps aux | grep unicorn I can see them :
deployer 19705 1.7 10.0 59404 50972 ? Sl 02:59 0:06 unicorn master -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
deployer 19709 0.0 10.5 65484 53848 ? Sl 02:59 0:00 unicorn worker -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
deployer 19712 0.0 10.5 65484 53824 ? Sl 02:59 0:00 unicorn worker -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
However /home/deployer/apps/blog/shared/pids contains only unicorn.pid and no unicorn.0.pid
Also if I try to find them with find (sudo find / -name "*.pid") :
Only the master appears...
Do you have any idea about it plz ?
Add this to the bottom of your unicorn.rb
so that each unicorn worker creates its own PID. See this post for more info.
Sorry, the problem with the above solution is that both the parent and child processes will write out their pid to the worker's pid file. We just want the child so change it to:
Has anyone got a monit template for Sidekiq and/or Redis?
I'm having a bit of a hard time setting the pidfiles up correctly with Unicorn Zero Downtime Deployments. This is where I'm at right now https://gist.github.com/3818705
I'm in the same boat. Did you ever get this working?
thx Ryan, so useful for me now.
Has anyone have an template for monitoring Passenger workers? I'm also finding so hard to include pid-file into my.cnf using MySQL. Any ideas?
I'm getting this error when running cap monit:setup
method_missing_with_variables': undefined methodtemplate' for #Capistrano::Configuration:0x8ce5a24 (NoMethodError)
I'm getting the same thing.. not sure what the deal is! Unless it has something to do with me not using the "templates" folder?...
I ran into this same issue...
template is a method that is defined in templates/base.rb
Here's a sudo template helper method to keep your code... DRY
Put it in
I've noticed that during deployments, monit will sometimes see that unicorn, sidekiq etc have no pidfiles so will try to start them before the deploy is completed. Does anyone have a solution for this?
I'm thinking of writing a capistrano lockfile when the deploy is started and removing it when finished, then monit can skip its checks for the affected services if the lockfile exists.
Why not just use Capistrano for deployment, and use a before stop hook and first stop monit, then after start, start monit?
Thanks for the suggestion Allen. This fixed my unicorn deploy woes and seems to be pretty clean.
I added these tasks:
And then these hooks:
If you only run a single server, you have to use a third-party service to monitor your server. Because if your server goes down, Monit will go down with it.
Here is an excellent article on monitoring : Monitoring and Maintaining Your Server