Skip to content

Instantly share code, notes, and snippets.

@raecoo
Last active October 26, 2022 06:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save raecoo/5001521 to your computer and use it in GitHub Desktop.
Save raecoo/5001521 to your computer and use it in GitHub Desktop.
Monit (http://mmonit.com/monit/) script example
set daemon 20
set logfile syslog facility log_daemon
set mailserver smtp.gmail.com port 587
username "ERROR-EMAIL-ADDRESS" password "PASSWORD"
using tlsv1
with timeout 30 seconds
set alert ERROR-EMAIL-ADDRESS
set httpd port 2812 and
use address localhost
allow localhost
allow admin:monit
check system localhost
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 90% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
check process nginx
with pidfile /var/run/nginx.pid
group www
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout
check process mysql
with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
check process redis
with pidfile /var/run/redis/redis-server.pid
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if failed host 127.0.0.1 port 6379 then restart
if 5 restarts within 5 cycles then timeout
group redis_workers
check process sidekiq
with pidfile /var/www/project-name/current/tmp/pids/sidekiq.pid
start program = "/bin/sh -c 'cd /var/www/project-name/current; PATH=/usr/local/bin:$PATH RAILS_ENV=production bundle exec sidekiq -C config/sidekiq.yml -P tmp/pids/sidekiq.pid" as uid deploy
stop program = "/bin/sh -c 'cd /var/www/project-name/current && kill -s INT `cat tmp/pids/sidekiq.pid`'"
if totalmem is greater than 200 MB for 10 cycles then restart # eating up memory?
group sidekiq_workers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment