Monit [How to] : Playing with Monit

Playing with Monit

How to auto start jvm server process if it die while i’m not in my laptop? how to know my server is overloaded? Monit can do that easily .

Here I will show you a little trick using monit.

Installation

  1. apt-get install monit OR wget http://mmonit.com/monit/dist/binary/5.4/monit-5.4-linux-x64.tar.gz
  2. tar xvfz monit-5.4-linux-x64.tar.gz
  3. cd monit-5.4/
  4. nano conf/monitrc
  5. Scroll to the bottom, then find this "include /etc/monit/conf.d/*", if it have a “#” in front of the code, remove it
  6. bin/monit -c conf/monitrc
  7. mkdir /etc/monit.d
  8. nano /etc/monit.d/localhost
  9. Insert the script, (look below)
  10. pkill monit (test if monit working, kill the monit process)
  11. bin/monit -c conf/monitrc
  12. If it says "Starting monit daemon with http interface at [192.168.0.245:2812]" it means Monit is working.
  13. Open your browser http://192.168.0.245:2812 (admin/monit)

The code

set daemon 20   # TIMEOUT 20 Seconds
set logfile syslog facility log_daemon  # LOGGING

set mailserver smtp.gmail.com port 587
         username "fajri@yahoo.co.id" password "PASSWORD"
         using tlsv1
         with timeout 30 seconds

set httpd port 2812 and
         use address 192.168.0.245
         allow localhost
         allow 192.168.0.0/255.255.255.0
         allow admin2:monit2
         allow 192.168.0.245

check process redis_stream
         matching "Redis_stream.php"
         start = "/usr/bin/php /home/fajri/php_project/php_twitter_phirehose/Redis_stream.php"
         if does not exist then start

Explanation

In my Monit script, I want to autostart twitter stream, sometime it stop, actually it kill by linux, because there’s no process, and linux guess it’s zombie process, so linux kill it. Whereas, it working fine, but no new tweet and process so low. And it’s working fine to me, when it stop, monit will starting it again.

Conclusion

This simple post is just to show how to use Monit. And in my opinion, it’s so helpfull for backend dev like me 😀

Update

So, I want to start monit when my server reboot, here is the script .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s