Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. It is pretty easy to configure and even easier to use. It comes with a simple web server to monitor statuses of the alerts you set (with basic HTTP authentication). On Monit W’k’ you can find configuration examples for different services. Just in case you need a configuration example for Memcached instances, here is what you need.
You need to run memcached with -P parameter to create a pid file, which Monit can monitor (and use to kill the process if needed). The configuration below is for a memcached instance running in deamon mode with root identity, creating a pid file at /var/run/memcached.pid, using 512Mb of memory and listening on port 11211 at localhost. If monit cannot connect to port 11211 at localhost anytime, it will automatically stop the service and restart it. if CPU usage gets higher then 60% for 2 monitor cycles it will send an alert, and if it gets over 98% for 5 cycles it will automatically restart the instance.
check process memcached with pidfile /var/run/memcached.pid start program = "/usr/local/bin/memcached -d -P /var/run/memcached.pid -u root -m 512 -l 127.0.0.1 -p 11211" stop program = "/bin/kill -9 `cat /var/run/memcached.pid`; rm /var/run/memcached.pid" if failed host 127.0.0.1 port 11211 then restart if cpu > 60% for 2 cycles then alert if cpu > 98% for 5 cycles then restart if 2 restarts within 3 cycles then timeout group cache