Last active
May 14, 2020 16:43
-
-
Save alobato/ffd1b761a9c801e769f063af9c2c396c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ sudo apt install monit | |
# $ sudo monit | |
# $ sudo systemctl enable monit // enable autostart | |
# $ sudo service monit reload | |
# $ sudo monit -t | |
# $ sudo monit validate | |
# $ sudo systemctl status monit | |
# $ sudo cat /var/log/monit.log | |
# $ ssh -NL 2812:localhost:2812 deployer@IP | |
# http://localhost:2812/ | |
# admin:monit | |
# /etc/monit/monitrc | |
set daemon 120 # check services at 2-minute intervals | |
with start delay 240 # optional: delay the first check by 4-minutes | |
set log /var/log/monit.log | |
set idfile /var/lib/monit/id | |
set statefile /var/lib/monit/state | |
set mailserver smtp.gmail.com port 465 | |
username "your@gmail.com" password "PASSWORD" | |
using tlsv1 | |
with timeout 30 seconds | |
set eventqueue | |
basedir /var/lib/monit/events # set the base directory where events will be stored | |
slots 100 # optionally limit the queue size | |
set mail-format { from: your@gmail.com } | |
set alert other@gmail.com # receive all alerts | |
set httpd port 2812 and | |
use address localhost # only accept connection from localhost | |
allow localhost # allow localhost to connect to the server and | |
allow admin:monit # require user 'admin' with password 'monit' | |
check system $HOST | |
if loadavg (1min) > 4 then alert | |
if loadavg (5min) > 2 then alert | |
if cpu usage > 95% for 10 cycles then alert | |
if memory usage > 75% then alert | |
if swap usage > 25% then alert | |
check process nginx with pidfile /var/run/nginx.pid | |
start program = "/usr/sbin/service nginx start" with timeout 60 seconds | |
stop program = "/usr/sbin/service nginx stop" | |
if failed port 443 protocol https request /version with content = "version" with timeout 7 seconds then alert | |
check host api with address api.DOMAIN.COM | |
if failed port 80 protocol http then alert | |
if failed port 443 protocol https status = 200 and request /path with content = "text" and certificate valid > 7 days then alert | |
check process mysql with pidfile /run/mysqld/mysqld.pid | |
start program = "/usr/sbin/service mysql start" with timeout 60 seconds | |
stop program = "/usr/sbin/service mysql stop" | |
if failed unixsocket /var/run/mysqld/mysqld.sock then restart | |
check filesystem datafs with path /dev/sda1 | |
if space usage > 80% for 5 times within 15 cycles then alert | |
if space usage > 99% then stop | |
if read rate > 1 MB/s for 5 cycles then alert | |
if read rate > 500 operations/s for 5 cycles then alert | |
if write rate > 1 MB/s for 5 cycles then alert | |
if write rate > 500 operations/s for 5 cycles then alert | |
check host myserver with address localhost | |
if failed ping then alert | |
if failed port 3306 protocol mysql with timeout 15 seconds then alert | |
check network public with interface ens3 | |
if failed link then alert | |
if changed link then alert | |
if saturation > 90% then alert | |
if download > 10 MB/s then alert | |
if total uploaded > 1 GB in last hour then alert | |
include /etc/monit/conf.d/* | |
include /etc/monit/conf-enabled/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment