I was seeing strange statistics on one of my memcached servers, so I had to see what was happening on it. I found some commands that can be used to sniff, extract, and gather statistics from a running memcached server. I collected them here if I’ve ever needed them again.
Debug GET commands
Show only GET commands sent to memcached
tcpflow -c dst port 11211 | cut -b46- | grep ^get
The cut command will remove the first 46 bytes of every string, which typically contains metadata like source, destination, and port. You may need to adjust the numeric parameter for cut to isolate the commands. The output should look like this:
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 to the end of the pipe to calculate the transfer rate:
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 the command rate instead of the transfer rate, add the -l (lines) parameter to the 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 to get you started with debugging. 😄
](https://gagor.pro/generic-cover.webp)