Using Monit process monitoring on Ubuntu/Debian
Monit is an open-source monitoring tool for Linux operating systems. This article guides you through a basic Monit setup on Ubuntu/Debian.
Installation
sudo apt-get update
sudo apt-get install monitConfiguration
The main configuration file is located at /etc/monit/monitrc. Open it for editing:
sudo nano /etc/monit/monitrcEnable the web interface
Uncomment and adjust the following lines to enable the HTTP status interface:
set httpd port 2812 and
use address localhost
allow localhost
allow admin:monitChange admin:monit to a username and password of your choice.
Monitor a process
Add a service check block. For example, to monitor nginx:
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeoutMonitor system resources
check system localhost
if loadavg (1min) > 4 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alertStarting Monit
sudo service monit start
sudo update-rc.d monit enableUseful commands
# Check Monit status
sudo monit status
# Test configuration syntax
sudo monit -t
# Reload configuration
sudo monit reload
# Stop a monitored service
sudo monit stop nginx
# Start a monitored service
sudo monit start nginxAccessing the web interface
Open a browser and navigate to:
http://your-server-ip:2812Log in with the credentials configured in monitrc.