How to set up a monit to monitoring server

Date : 06/03/2019

Introduction

Monit is an open source monitoring tool. monit is also used to manage files, programs directories, and even devices to check timestamp changes, size changes, checksum changes, TCP/IP change, protocol changes, etc. so make use of it your server and get benifit from it.

Usage :

  1. system logs monitor.
  2. Health Monitoring on hardware such as (hard disk, motherboard, etc)
  3. sshd monitoring.
  4. Check system load, SWAP, RAM usage.
  5. Check server status (offline/online)

Step by step procedure as follows:

1. Download Monit

# sudo rpm -ivh https: //dl.fedoraproject .org/pub/epel/epel-release-latest-7.noarch.rpm

2. Install Monit

Download and then install it.

# yum install monit

3. Enable and start Monit

After installed then enable and start it, because it is the foremost step

# systemctl enable monit

# sytemctl start monit

4. Check status

Then check the status, whether it is started properly or not.

# monit status

5. Configuring Monit
By default, Monit is configured to check a server every 30 seconds. We can alter this to any interval of time required.

In the example below, I have set it to 60 seconds.

To edit the Monit config file go to /etc/monit.conf

nano /etc/monitrc

set daemon 60

Now let’s setup Monit to work on port 2812:

First open the configuration file at /etc/monit.conf

vi /etc/monit.conf

Next, from the existing settings:

set httpd port 2812
use address localhost
allow localhost

allow admin:monit
allow @monit

allow @users readonly

Change to your own usage settings:

set httpd port 2812
allow 0.0.0.0/0.0.0.0
allow admin:monit

Here, username is admin and password is monit. After you change to settings above, Monit will listen to port 2812. The admin user can access the web interface via any network.

Finally restart Monit to make changes effective:

# restart monit.service

Then, open your web browser and type in http://your-ip-address:2812 to access web interface in your desired browser.

6. Monitor Apache with Monit
We can also add other services to the monitoring system. As usual, edit the configuration file is located at /etc/monit.conf

check process apache with pidfile /var/run/httpd.pid
start program = “/etc/init.d/httpd start” with timeout 66 seconds
stop program = “/etc/init.d/httpd stop”

Example of adding apache:

Then restart monit.

You can then check monit’s summary by typing the command monit summary and you will see a process called ‘apache’ running.

# monit summary

7. Add monitoring for syslog.

check process syslogd with pidfile /var/run/syslogd.pid
start program = "/usr/bin/systemctl start rsyslog.service”
stop program = "/usr/bin/systemctl stop rsyslog.service”

Reload Monit to see the changes quick and effective

# monit reload

Thanks for using pheonix solutions.

You find this tutorial helpful? Share with your friends to keep it alive.

Leave a Reply