Open In App

Monitor Linux Daemon, Filesystem, CPU, Network and Files Using Monit

Last Updated : 11 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Monit is a utility tool for monitoring & managing processes, files, directories, and filesystems on a Unix System. A superpower or a super ability to start a process if it’s not running, restart a process if it isn’t responding, and stop a process if it uses high resources, that’s what Monit(or) does in layman’s terms.

Monitoring is basically treated as an additional feature of Monit. Using it you can monitor files, directories, and filesystems for changes such as checksum changes also changes with file size or changes to the timestamp. This small Open Source utility for managing and monitoring Unix based systems. Monit can conduct various forms of automatic maintenance and create repair reports which can be helpful in executing meaningful causal actions in error situations.

Installation:

This open-source tool can be downloaded with the simple apt-get command. Open the terminal and write the following commands.

sudo apt-get install monit

monit installation

To check the version use this command. 

monit --version

monit version

We can start and enable the Monit service with the following command.

systemctl start monit
systemctl enable monit

Then check the status of the Monit with the following command.

systemctl status monit

monit status

Configuration for Web-Interface

Monit has it’s own user-friendly web-interface. By default, it is disabled to enable it to follow the following section. With it, you can view the system status & manage the properties through the web-browser.

We will start by editing it’s configuration file /etc/monit/monitrc

sudo nano /etc/monit/monitrc

Un-comment the following lines from monit. This will allow the interface to run on localhost port 2812.  

Configuration for Web-Interface

Save and restart the Monit service 

systemctl restart monit

Go to localhost:2812 and when prompted type Username as “admin” and password as “monit”. Without double quotes.

You should see a default dashboard like the one shown below.

Configuration for Web-Interface

Click on the example system shown (hazard) to view to the status of the server.

Configuration for Web-Interface

Monitrc can also be configured to change the timings daemon process in seconds to know how often it is going to view the status of the service.

With default settings, it checks immediately after we launch the monit. Simply remove or change the delay option to change the delay timings. TPolling frequency (This is the interval (in seconds) at which Monit runs its tests.)

Configuration for Web-Interface

To restart Monit use following command

sudo /etc/init.d/monit restart

To verify Monit logs

sudo tail -f /var/log/monit.log

Configure Monit for Additional Services

Apache, SSH and FTP

Install Apache and vsftpd to the system with the following command.

sudo apt-get install apache2 vsftpd

Now, create a configuration file for vsftpd.

sudo nano /etc/monit/conf-available/vsftpd

Add these line to vsftpd:

check process vsftpd with pidfile /var/run/vsftpd/vsftpd.pid
  start program = "/etc/init.d/vsftpd start"
  stop  program = "/etc/init.d/vsftpd stop"
if failed port 21 protocol ftp then restart

Save and close nano and enable the configuration file by creating a symbolic link.

sudo ln -s /etc/monit/conf-available/vsftpd /etc/monit/conf-enabled/

Also, enable Apache and SSH configuration file in similar way.

sudo ln -s /etc/monit/conf-available/apache2 /etc/monit/conf-enabled/
sudo ln -s /etc/monit/conf-available/openssh-server /etc/monit/conf-enabled/

and verify monit status

monit -t

then restart monit

systemctl reload monit

To check the status of services like CPU, File System and Network, use the following command

sudo monit status

monit status service


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads