I had strange statistics on one memcached servers. I had to look what it’s doing there. I found such commands1 that may be used to sniff, extract and make statistics from running memcached server.

Debug GET commands

Show only GET commands sent to memcached
tcpflow -c dst port 11211 | cut -b46- | grep ^get

cut command will remove 46 bytes at beginning of every string (src, dst, port). You may need to adjust numeric parameter for cut to leave commands only. Output should look like:

Example output of GET commands
get myapp-cache-theme_registry
get myapp-cache_field
get myapp-cache-schema
...

Debug everything except GET commands

Show all commands except GET sent to memcached
tcpflow -c dst port 11211 | cut -b46- | grep -v ^get

Check transfer

Add pv -r at the end to calculate transfer:

Show transfer rate for GET commands
$ tcpflow -c dst port 11211 | cut -b46- | grep ^get | pv -r > /dev/null
tcpflow[11140]: listening on eth0
[8.25kB/s]

Check command rates

To check command rates not the transfer add -l param (stands for lines) to pv command:

Show command rate for non-GET commands
$ tcpflow -c dst port 11211 | cut -b46- | grep -v ^get | pv -rl > /dev/null
tcpflow[9271]: listening on eth0
[1.51k/s]

That should be enough for you to start debugging 😄