Skip to content

Instantly share code, notes, and snippets.

@fuhry
Created November 16, 2017 14:02
Show Gist options
  • Save fuhry/83691b232a560acd4a22527047954c5f to your computer and use it in GitHub Desktop.
Save fuhry/83691b232a560acd4a22527047954c5f to your computer and use it in GitHub Desktop.
mcdump: dump memcache slabs
#!/bin/bash
# dumps memcache slabs.
SERVER=${1:-127.0.0.1}
PORT=${2:-11211}
export GREP_OPTIONS=
exec 3<>/dev/tcp/$SERVER/$PORT
puts() {
echo -en "$*\r\n" >&3
}
gets() {
local _line
read _line <&3
echo ${_line} | tr -d "\r"
return $result
}
close() {
exec 3>&-
exec 3<&-
}
trap close EXIT
puts "stats slabs"
slabs=()
lastslab=0
while line=$(gets); do
[[ "$line" == "END" ]] && break
slabno=$(echo "$line" | sed -re 's;^STAT ([0-9]+):[a-z_]+ [0-9]+$;\1;' | egrep '^[0-9]+$' || echo 0)
if [[ $slabno > 0 && $slabno != $lastslab ]]; then
slabs=(${slabs[@]} $slabno)
lastslab=$slabno
fi
done
for s in ${slabs[@]}; do
puts "stats cachedump $s 100"
echo "Slab $s:"
while line=$(gets); do
[[ "$line" == "END" ]] && break
echo " $line"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment