set daemon 30 with start delay 30 set log syslog set mailserver localhost set mail-format { from: ${monit['from_address']} } % for alert_address in monit['alert_addresses']: set alert ${alert_address} % endfor set httpd unixsocket /var/run/monit.sock use address 127.0.0.1 allow 127.0.0.1 check system $HOST if cpu usage > 95% for 10 cycles then alert if memory usage > 80% then alert if swap usage > 25% then alert check filesystem rootfs with path / if space usage > 80% for 5 times within 15 cycles then alert if space usage > 90% then alert if inode usage > 90% then alert check process cron matching "/usr/sbin/cron" start program = "/usr/bin/systemctl start cron.service" stop program = "/usr/bin/systemctl stop cron.service" % for systemd_service in ('systemd-timesyncd', 'systemd-networkd', 'systemd-journald'): check process ${systemd_service} matching "/lib/systemd/${systemd_service}" start program = "/usr/bin/systemctl start ${systemd_service}.service" stop program = "/usr/bin/systemctl stop ${systemd_service}.service" % endfor check process sshd matching "/usr/sbin/sshd" start program = "/bin/systemctl start sshd.service" stop program = "/bin/systemctl stop sshd.service" if failed port 22 for 2 cycles then restart if 3 restarts within 5 cycles then alert % for service,options in sorted(monit.get('services', {}).items()): check process ${service} matching "${options['bin']}" start program = "/bin/systemctl start ${options.get('systemd_unit', 'service')}.service" stop program = "/bin/systemctl stop ${options.get('systemd_unit', 'service')}.service" % for port,port_options in sorted(options.get('ports', {}).items()): if failed port ${port} protocol ${port_options['protocol']} for ${port_options.get('cycles', '5')} cycles then restart % endfor % for domain,http_options in sorted(options.get('http', {}).items()): if failed host ${domain} % if http_options['scheme'] == 'https': port 443 protocol https % else: port 80 protocol http % endif then restart % endfor % endfor