Skip to content

Instantly share code, notes, and snippets.

@codypo
Created April 6, 2011 14:21
Show Gist options
  • Save codypo/905730 to your computer and use it in GitHub Desktop.
Save codypo/905730 to your computer and use it in GitHub Desktop.
Monit example for restarting a service on excessive memory consumption
# Relevant example from our monitrc file.
check process couchdb with pidfile /usr/local/var/run/couchdb/couchdb.pid
start program = "/etc/init.d/couchdb start"
stop program = "/etc/init.d/couchdb stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if memory usage > 70% MB for 5 cycles then restart
@jmodjeska
Copy link

Try totalmem. Example httpd rule (Amazon Linux/CentOS/RHEL):

check process httpd with pidfile /var/run/httpd/httpd.pid
    start program = "/usr/sbin/httpd -k start"
    stop program = "/usr/sbin/httpd -k stop"
    if totalmem > 100 MB for 2 cycles then alert
    if totalmem > 1000 MB for 2 cycles then restart

@mactyr
Copy link

mactyr commented Sep 16, 2020

In the original example, if memory usage > 70% MB for 5 cycles then restart seems ambiguous. It looks like it should either be % or MB in the documentation, not both. I would guess that in this case monit would use the % and ignore the MB (or maybe throw an error?) but I'm not sure and it doesn't seem like a good idea to have the ambiguity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment