Quick Intro To Memcached Stats

The memcached logoA few days ago I was given the job of changing the caching engine used in a Zend Framework based application from a simple flat file system based caching system to a memcached based object store that could be used by multiple servers.

After extending the existing application bootstrap file to support the new cache mechanism. I started to wonder how I can get information on object store and the items it contains, with a file system cache you only have to look in the cache directory to see any cached items. A Memcached instance is not a closed system though stats can be requested on demand, so I hope to cover off some basic methods of interacting with a memcached instance here.

Telnet

The easiest way to interact with your memcached instance is by using telnet. You can simply connect to the port that memcached is running on. This will give you a prompt that can be used to execute commands    to retrieve information about the service.

For example to connect to a local memcached instance running on the default port 11211 you would execute at the command line:

telnet localhost 11211

Telnet Commands

After connecting to the memcached instance over telnet. There are a number of commands which can be executed to find out more about the object cache.

To display general purpose statistic like the uptime, number of connections, version etc of the memcached instance simply type “stats” at the prompt and hit enter.

For more information about the items stored in the cache you can execute the command “stats items”. This will give you things like the item count, age, eviction etc. One entry returned by this command that is wise to watch is evictions. In an ideal world the number of evictions reported for your object cache should be zero. If this is higher at your cache is probably running out of memory to store objects.

For more detailed information on memory usage of the instance you can also use command “stats slabs”.

The whole process of gathering stats can even be automated a little with the use of netcat and watch. To give a kind of “top” like output from memcached with the command:

watch “echo stats | nc 127.0.0.1 11211”

Further Reading:

Memcached project site

Memcached Munin Plugin

Leave a Reply

Your email address will not be published. Required fields are marked *