Oct 1, 2010

Zabbix's template to monitor Memcached

Today's topic is about monitoring Memcached instance. There are several ways/tools to monitor Memcached such as Munin, Nagios and Zabbix. I used to work with several monitoring tools but the most effective & my favorite one is Zabbix. I will discuss my impression about Zabbix later.

How to monitor Memcached's instance by using Zabbix
  1. Import Memcached's template from this link to your Zabbix server
  2. Modify /etc/zabbix/zabbix_agentd.conf and add the following UserParameter (on the Memcached server)
    UserParameter=memcached_stats[*],echo -e "stats\nquit" | nc 127.0.0.1 $1 | grep "STAT $2 " | awk '{print $$3}'
  3. Restart Zabbix agentd service
  4. Link Mecached template to Memcached server
  5. Check the latest data (Application: memcached)
What are inside this template
  • 38 Items (default type is Zabbix Agent Active)
  • 1 trigger
  • 4 graphs
Note
  • This template tries to monitor Memcached instance that running on port 11211
  • If your Memcached instance is running in different port, you could simply replace 11211 with your port number before importing this template
  • If you run more than one Memcached instances, you could simply copy this and modify port number.

10 comments:

Alouit Alexandre said...

Hi,
I had some problems with the template, I had to replace "Type" "Zabbix agent (active) " by "Zabbix agent" on all elements,

and I also added "unit" Bytes to the elements "CS_Memcached_11211:limit maxbytes","CS_Memcached_11211:bytes_written","CS_Memcached_11211:bytes_read".

But otherwise this tutorial is great, thank you very much!

AuntiSpam said...

Thank you for your feedback. I'll recheck the template as your suggestion.

Unknown said...

Thanks a lot for your job! Works perfect for me ! Easy, simple and well explained.

I had to replace "Type" "Zabbix agent (active) " by "Zabbix agent" on all elements, to add "unit" Bytes to the elements limit_maxbytes,bytes_written, bytes_read and unit "uptime" to time.

Anonymous said...

Cool!

I've only have a problem with the type of the items in our template, i've update all items to agent type, WHITOUT ACTIVE.

Thank you so much, this is a big job!

Jaime Herazo B. said...

Interesting note: debian/ubuntu has more than one variation of netcat, the official one and another one with modifications from openbsd (packages netcat-traditional and netcat-openbsd).

The openbsd version doesn't seem to work for me, it ignores the piped-in stdin. So instead of running "nc" to get the stats i use "nc.traditional".

Just a minor detail to have in mind if it should be working but isn't

Unknown said...

Hi!

Thank you!

Unknown said...
This comment has been removed by the author.
Unknown said...

Just one tip

Unless UnsafeUserParameters agent daemon configuration option is enabled, it is not allowed to pass flexible parameters containing these symbols: \ ' ” ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @

;)

Danny Sokolovski said...

Thanks for this great template, i used ubuntu & had to change the command to:
UserParameter=memcached_stats[*],(echo stats; sleep 0.1) | telnet 127.0.0.1 $1 2>&1 | awk '/STAT $2/ {print $NF}'

with nc i coudn't make it work not even with other nc types. so telnet worked just fine !

Danny Sokolovski said...

better adding space after the $2

UserParameter=memcached_stats[*],(echo stats; sleep 0.1) | telnet 127.0.0.1 $1 2>&1 | awk '/STAT $2 / {print $NF}'