Monitor Your Network Effectively with Monit
Monit is a utility for monitoring and managing programs, processes, files, directories and filesystems on UNIX and Linux systems. Monit monitors systems, maintains them automatically and even repairs them. This article deals with its installation and conf
Do you want to know more about what to do if your server goes down? Well, if you have only a little or no idea about network monitoring but are willing to delve into it, Monit gives you a start with the minimum effort. At the very elementary level, an SNMP (Simple Network Management Protocol) relies on just two basic things—a management server and a managed device. The management server retrieves information from the managed devices and stores it in the information table. However, this data is useless until it's presented properly for the end user. For this, you need a network monitoring tool. And if you are a beginner, you can get nothing better than Monit to start with.
According to Wikipedia, Monit “...is a free, open source process supervision tool for UNIX and Linux.” It is written in C by Tildeslash Ltd with its latest stable release being 5.5, and is licensed under the GNU General Public License 3.0. It gained popularity after its use with Ruby on Rails and the Mongrel Web server, since it suits the diverse needs of both.
Features
Monit is an open source utility that is designed for the management and monitoring of the various processes and programs running at a time—the files, directories and more— on a Linux or UNIX system. Although it has a distinctly large number of features, what actually makes it different is its ability to conduct automatic maintenance, i.e., it can execute causal actions, automatically, at the time the error occurrs. The following are some features of Monit: It monitors the daemon processes or similar ones at the localhost. The daemon processes include programs such as Apache, MySQL, Sendmail and the like. It monitors files and directories on the localhost, and is useful in keeping a check on the MD5 or SHA1 checksum of files. It gives alerts if a change is detected. It monitors network connections to servers, whether it is on the localhost or on a remote server. It monitors general system resources on the localhost such as CPU usage, memory and much more.
Monit can act automatically when an error occurs. For instance, if your Apache server is using too many resources, it can automatically restart Apache and send you an alert message.
Installation
Monit is meant for Linux and UNIX systems, so all you need to do is open your command line and type in the commands given below. It’s just that simple.
For Debian-based Linux distros, the command is:
For RPM-based systems, such as Fedora, CentOS and more, you need to work a little harder. Let’s first install some prerequisites, as follows:
Now you need to download the latest version of Monit from http://mmonit.com/monit
Extract the tar file now, as follows:
Compile from the source:
Configuring and running Monit
By now, your system is up with Monit, and ready to retrieve and display system information. Along with the other great features, Monit possesses a great Web interface on Port 2812. All you need to do now is edit the Monit config file monitrc located at / etc/monit/ , according to your information needs. Let's get started.
First, you need to either edit the file or change file permissions by command, as the root user:
The very first thing you probably want to configure is enabling the Web interface. Just add the following commands:
With the above configuration, you can browse to the location server.example.net:2812 from your browser, with username and password as the login credentials.
Next, let’s configure Monit for email alerts, as follows:
In the above configuration, smtp.example.net is an SMTP server, whereas the smtp-username and smtppassword are your login credentials. Much of all this is self-explanatory.
Monitoring the system
To monitor the general health and resources of the system, you need to append the lines below to the monitrc file:
Monitoring Apache Web server
To monitor Apache, you need to find the Apache process section in the monitrc file and uncomment it to produce the following result. Don't forget to take care of the pid file.