Overview

Monit is popular third-party monitoring software for Unix systems that allows you to automate the need, in many cases, to restart unresponsive processes. MySQL crashed and is now unresponsive? Monit can email you about it, restart it, or both. Even the entire server can be restarted based on whatever criteria you prefer to monitor for. The end-result of this advanced guide will be to install a basic Monit configuration that monitors all core server processes. Please keep in mind that installing or maintaining Monit falls outside of the (mt) Media Temple Scope of Support; this guide is provided as a courtesy to assist you in the advanced customization of your server.

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by Media Temple. Please take a moment to review the Statement of Support.

NOTE:

Installing Monit will not fix the core problems that cause system services to go unresponsive. Monit is designed to make babysitting any resulting up-time issues during your troubleshooting much less painful, but it will not automatically fix an ongoing issue.

Instructions

As a prerequisite to installing Monit, you'll want to make sure you have "development tools" installed. This can be done with the following command:

yum -y groupinstall "development tools"

Next, you will want to download and unpack Monit. For organizational purposes, it is good practice to use /usr/local/src. That way, you always know where to find the temperamental data/source code you use for new installations.

First, step into the /usr/local/src directory:

cd /usr/local/src

Then, download and unpack Monit:

wget http://mmonit.com/monit/dist/monit-5.6.tar.gz

tar zxf monit-5.6.tar.gz

rm -f monit-5.6.tar.gz

cd monit-5.6

From here, Monit needs to be built from source. We'll use a fairly vanilla configuration, The following command will change the prefix so it is set to /usr rather than /usr/local (which is what Monit will default to). This is primarily to keep an extra degree of separation between Plesk, which lives in /usr/local/psa, and other software on the system. This will also configure Monit without the PAM option.

./configure --prefix=/usr --without-pam

make

make install

mkdir /etc/monit.d/

The first thing that Monit needs is a configuration file. The command below will pull the username, password, and email address alerts are to be sent to, using information already stored in Plesk:

If you would prefer that either the username or password to be independent of your Plesk login credentials, you'll need to edit the command below accordingly with your own information. For example, replace /usr/local/psa/bin/admin --show-password with the password of your choice.

To help things keep manageable, we can now create a few scripts to ensure that this information stays up-to-date. This way, if you change either your Plesk password or your email address, Monit will also be updated. If you manually edited the command above to include different information, skip the corresponding step(s) below.

Skip the following commands if you do not want Monit's email address to match Plesk's administrator email:

Unfortunately, Plesk does not currently provide an event handler for the admin password changing, so updating other software with these credentials will require a custom cron job.

Create the config extensions directory:

mkdir /etc/monit.d/

With a configuration file now ready to go, we now need to add variables to be monitored using Monit. Please see the section on "Sample Configurations" below for some examples you can use to get the most out of this versatile software.

Next, you'll want to set up Monit to start automatically when your server reboots:

cp contrib/rc.monit /etc/init.d/monit

chmod 755 /etc/init.d/monit

chkconfig --level 235 monit on

All done! Time to start Monit:

/etc/init.d/monit start

If everything is working correctly, you'll see a message similar to the following:

Sample Configurations

Below are several optimized configurations you can use to populate Monit with alerts once installed. Some users may find the thresholds for email alerts and/or restarts to be overly conservative, and can edit each respective command accordingly. Users may pick and choose accordingly if they do not want all of the following checks added to Monit; they are all entirely independent of each other: