Tuesday, 26 June 2012

Using Monit to monitor a Redis instance

I have been using Redis for a long time now (since version 1.x) - the challenge has been how to start and manage an instance and get alerts when it is consuming too much memory.  This is where Monit comes in - it can monitor various Unix daemons and provide a single dashboard to view status, manage restarts etc.,

Here is how I have configured monit to watch redis


 check process redis with pidfile /var/run/redis.pid
   group redis
   start program = "/usr/local/bin/redis-server /etc/redis/redis.conf"
   stop  program = "/usr/local/bin/redis-cli shutdown"
   if failed unixsocket /var/redis/redis.sock
        send "SET MONIT-TEST value\r\n"
        expect "OK"
        send "EXISTS MONIT-TEST\r\n"
        expect ":1"
   then restart
   if 2 restarts within 2 cycles then alert

This worked fairly well with Monit not only monitor an instance but also tries to put a key and test and make sure that the redis instance is running fine.

No comments:

Post a Comment