Yet another Zabbix template to monitor Memcache

Similar to my search for an efficient way to monitor UBC values on an OpenVZ hardware node, existing methods of monitoring a memcached server available on the net didn’t make me happy.

So, here we go: instead of the common method of using a simple UserParameter to connect to the memcached server via telnet and obtain the result of the STAT command (for each item!), I prefer to parse the results of the STAT command once and then send the interesting bits to the Zabbix server. This means I telnet to the memcached server only once instead of for each single item I want to monitor.

The obvious drawback is that this won’t work as a passive check. So I set up a cronjob which calls my script to do work every five minutes. Since I trust the cron daemon on my servers, this is not a big issue for me.

To cut a long story short, here is the script which reads and parses the output of the memcache STAT command and then send interesting bits of it to the Zabbix server: and the Zabbix template: zabbix_memcached_template.xml

Put the script somewhere on the host where memcached runs (or on another host which can reach the host with memcached running) and adjust the few options at the top of the script. I used a special configuration zabbix_sender.conf which is a stripped down version of the usual zabbix_agentd.conf just to configure the zabbix_sender utility without activating active checks for the agent, it has the following content:

ServerActive=[zabbix server ip]:[port];
SourceIP=[source ip];
Hostname=[hostname as configured in zabbix];

Then import the template on your Zabbix server and set up a cronjob for the script:

*/5 * * * *  zabbix /usr/bin/python /etc/zabbix/user/

The script and template has only been tested with Zabbix 2.0. Most likely it won’t work with Zabbix 1.x.