Adjusting MySQL Monit Memory

1 min read

GridPane uses Monit to manage services and restart them if they start misbehaving.

We set MySQL to restart if it starts using too much CPU or Memory.

Sometimes you might wish to adjust these settings yourself if you think Monit is restarting MySQL too often. This is most likely to be the case if you need to adjust its memory headroom.

This is a typical Monit MySQL configuration for a 1GB Server, it can be found here:

nano /etc/monit/conf.d/mysql
Check process mysql with pidfile /var/run/mysqld/mysqld.pid
    group database
    group mysql
    start program = "/usr/sbin/service mysql start"
    stop program = "/usr/sbin/service mysql stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 70% for 3 cycles then exec "/usr/local/bin/gpslack MYSQL_HOT warning"
    if cpu > 90% for 5 cycles then restart
    if mem > 550 MB for 3 cycles then restart
    if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4 cycles then restart
    if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then restart
    if 3 restarts within 5 cycles then exec "/usr/local/bin/gpslack MYSQL error"

As you can see, Monit allows MySQL to run with just over 50% of the available RAM, we consider this about right for such a small server, but you might want to adjust this.

To do so, edit this line to increase the RAM before Monit triggers a restart:

if mem > 650 MB for 3 cycles then restart

And then reload Monit

monit reload