Self-Monitoring using Monit in Rails
We value our customers a lot and so we use all the tools and services to make our client’s application highly available in production. Monit is one of the tools we use in production to ensure that all essential services and applications are up and running.
This post explains how to configure Monit for commonly used tools and services with a rails application.
Installing Monit on Linux is super easy. Checkout the steps mentioned in previous post for more details.
Once the Monit is installed, you can add applications and tools you want to monitor in /etc/monit/monitrc
configuration file like as below. Here are configurations of some of the most common applications used with Rails:
Nginx
check process nginx with pidfile /var/run/nginx.pid start program = "/etc/init.d/nginx start" stop program = "/etc/init.d/nginx stop"
MySQL
check process mysqld with pidfile /var/run/mysqld/mysqld.pid start program = "/etc/init.d/mysql start" stop program = "/etc/init.d/mysql stop"
Apache
check process apache with pidfile "/var/run/httpd.pid" start program = "/etc/init.d/httpd start" stop program = "/etc/init.d/httpd stop"
Mongo
check process mongodb with pidfile /var/run/mongodb.pid start program = "/etc/init.d/mongodb start" stop program = "/etc/init.d/mongodb stop"
Redis
check process redis with pidfile /var/run/redis.pid start program = "/etc/init.d/redis start" stop program = "/etc/init.d/redis stop"
Unicorn
check process unicorn with pidfile /home/USER_NAME/APP_NAME/shared/pids/unicorn.pid start program = "/etc/init.d/unicorn start" stop program = "/etc/init.d/unicorn stop"
Delayed Jobs
Monit does not have Rails and RVM environment variables so that cannot start delayed_job directly like as other services defined above.
Solution :
- Create /home/USER_NAME/APP_NAME/shared/delayed_job.monitrc
- Add the code for start and stop services in /home/USER_NAME/APP_NAME/shared/delayed_job.monitrc file. Do not add this code in /etc/monit/monitrc.
- Create new bash file /etc/init.d/delayed_job init script for monit to start the delayled_job.
- Change its access mode to 755, edit /etc/init.d/delayed_job bash file and add following script.
Finish Up
Once you have configured all of the programs, reload the Monit.
$ sudo monit reload
and start running all of the monitored programs by following command:
$ sudo monit start all
You can check the logs for all running process into /var/log/monit.log file.
Here you can find many more examples of how to configure other services like cron, File, FTP, mail etc.
Happy Monitoring!!
How To Install and Configure Monit | DigitalOcean
Monit is a helpful program that automatically monitors and manages server programs to ensure that they not only stay…
http://www.digitalocean.com
Use monit daemon to monitor Ruby on Rails delayed_job
Reason monit does not have Rails and RVM environment variables so that cannot start delayed_job Solution Create /etc…
http://alantsui.hk
At BoTree Technologies, we build web and mobile applications to add value to our client’s business. We align ourselves to ensure that our client benefits the most out of our engagement.
We work in Ruby on Rails, Python, Java, React, Android, iOS and RPA as well.
Drop us a line to discuss how can we help take your business to the next level.