Installing and Configuring Monit on Ubuntu

Bill Liu
2 min readAug 17, 2024

--

## Installation

To install Monit on Ubuntu, follow these steps:

1. Update your system’s package list:
```
sudo apt update
```

2. Install Monit:
```
sudo apt install monit -y
```

3. Start the Monit service and enable it to run on system boot:
```
sudo systemctl start monit
sudo systemctl enable monit
```

4. Verify the installation by checking Monit’s status:
```
sudo systemctl status monit
```

## Configuration

After installation, configure Monit by editing the main configuration file:

```
sudo nano /etc/monit/monitrc
```

Add or modify the following configurations:

### Email Notifications

```
set mailserver smtp.gmail.com port 587
username “abc@abc.com” password “xxxxxxx”
using tlsv12
with timeout 30 seconds

set alert abc@abc.com
```

This setup configures Monit to send email alerts using a Gmail account.

### System Checks

```
check host google-ping with address 8.8.8.8
if failed ping then alert

check system localhost
if memory usage > 60% then alert
if cpu usage > 60% for 5 cycles then alert
if loadavg (15min) > 8 then alert

check filesystem rootfs with path /
if space usage > 80% then alert
if space usage > 90% then alert
if inode usage > 80% then alert
```

These checks monitor ping to Google’s DNS, system resource usage, and filesystem space.

### Web Interface

```
set httpd port 10001
use address 0.0.0.0
allow 127.0.0.1
```

This configuration enables Monit’s web interface on port 10001, accessible only from localhost.

## Applying Changes

After making changes to the configuration file:

1. Check the configuration for syntax errors:
```
sudo monit -t
```

2. If no errors are found, restart Monit to apply the changes:
```
sudo systemctl restart monit
```

With these configurations, Monit will monitor your system’s health and send alerts when predefined thresholds are exceeded. Remember to replace the email address and password with your actual credentials, and adjust the monitoring thresholds as needed for your specific use case.

--

--