Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created September 17, 2013 16:20
Show Gist options
  • Select an option

  • Save tonetheman/6596687 to your computer and use it in GitHub Desktop.

Select an option

Save tonetheman/6596687 to your computer and use it in GitHub Desktop.
bash command to trace leaking redis connections in node, used in debugging node and redis!
# get a list of processes first
# grep for node
# grep to remove the grep lines
# print the pids
# awk -vORS=, starts awk and sets the record separator to be the ","
# the print $1 just prints the stuff piped in (each pid in this case)
# the sed at the end takes the trailing comma ,$ and puts a return
# change the sed to 's/,$//' to just remove it and not put the return
# got the idea for the comma list grep from here
# http://stackoverflow.com/questions/8714355/bash-turning-multi-line-string-into-single-comma-separated
PIDS=`ps -eaf | grep node | grep -v grep | awk -F" " '{print $2}' | awk -vORS=, '{print $1}' |sed 's/,$/\n/'`
echo "PIDS for node currently: $PIDS"
TOTAL_REDIS_CONN=`lsof -p ${PIDS} | grep 6379 | wc -l`
echo "total redis connections: ${TOTAL_REDIS_CONN}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment