Enrico Boldori / Wiki

« Go back ⤓ Download

Linux - Ubuntu - Monit configuration.txt

# /etc/monit/monitrc
# Check services every X seconds
set daemon 60

# Define where monit should log events
set log /var/log/monit.log

# Define where monit should save the instance id
set idfile /var/lib/monit/id

# Define where monit should save the monitoring state on each cycle
set statefile /var/lib/monit/state

# Define the events queueing options
set eventqueue basedir /var/lib/monit/events slots 100

# Define who should receive the alerts
set alert admin@domain.tld

# Define which mailserver(s) to use for alert delivery
set mailserver mailserver.domain.tld
        username "user@domain.tld"
        password "secret-password"
        using SSL

# Override the default mail format or part of it
set mail-format { from: info@domain.tld }

# --------------------------------------------------

check system $HOST
        if loadavg (1min) > 4 then alert
        if loadavg (5min) > 2 then alert
        if memory usage > 85% for 3 cycles then alert

check process apache with pidfile /var/run/apache2/apache2.pid
        start program = "/bin/systemctl start apache2" with timeout 60 seconds
        stop program  = "/bin/systemctl stop  apache2"
        if cpu > 80% for 2 cycles then alert
        if cpu > 90% for 10 cycles then alert

check process mysql with pidfile /var/run/mysqld/mysqld.pid
        start program = "/bin/systemctl start mysql" with timeout 60 seconds
        stop program  = "/bin/systemctl stop  mysql"
        if cpu > 80% for 2 cycles then alert
        if cpu > 90% for 10 cycles then alert

check process ssh with pidfile /var/run/sshd.pid
        start program = "/bin/systemctl start ssh" with timeout 60 seconds
        stop program  = "/bin/systemctl stop  ssh"

# --------------------------------------------------

# Include additional configuration files
include /etc/monit/conf.d/*
include /etc/monit/conf-enabled/*