Monit configuration to monitor Memcached instances

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

Comments

set daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@domain.com }
set alert monit@domain.com
set httpd port 2812 and
allow admin:test

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 19627 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

check process memcached with pidfile /var/run/memcached.pid
start program = "/usr/local/bin/memcached -d -P /var/run/memcached.pid -u root -m 4096 -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

check process proftpd with pidfile /var/run/proftpd.pid
start program = "/etc/init.d/proftpd start"
stop program = "/etc/init.d/proftpd stop"
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout

check process mysql with pidfile /var/lib/mysql/hoster.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

check process apache with pidfile /var/run/apache2.pid
group www
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host melisbek.com port 80 protocol http
and request "/monit/token" then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 500 MB for 5 cycles then restart
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 postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout

# cron
check process cron with pidfile /var/run/crond.pid
group system
start program = "/etc/init.d/cron start"
stop program = "/etc/init.d/cron stop"
if 5 restarts within 5 cycles then timeout
depends on cron_rc

check file cron_rc with path /etc/init.d/cron
group system
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor

check process dovecot with pidfile /var/run/dovecot/master.pid
start program = "/etc/init.d/dovecot start"
stop program = "/etc/init.d/dovecot stop"
group mail
if failed host mail.drupion.org port 993 type tcpssl sslauto protocol imap for 5 cycles then restart
if 3 restarts within 5 cycles then timeout
depends dovecot_init
depends dovecot_bin
check file dovecot_init with path /etc/init.d/dovecot
group mail
check file dovecot_bin with path /usr/sbin/dovecot
group mail

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To