Skip to content

Instantly share code, notes, and snippets.

@maxrp
Last active December 17, 2015 20:19
Show Gist options
  • Save maxrp/5666542 to your computer and use it in GitHub Desktop.
Save maxrp/5666542 to your computer and use it in GitHub Desktop.
Fuckin' threads. Fuck 'em.
#!/usr/bin/bash
USERNAME=''
PASSWORD=''
THRESHOLD='1000'
SLO_THREADS=$(mysqladmin -u$USERNAME -p$PASSWORD proc | egrep -v 'Sleep|Time|Id|processlist' | awk -F'|' '{print $7,$2,$9}' | sort -bnr | sed '/^[ \t\n]*$/d' | head -5 )
date
while read -r line; do
IFS=' ' read -a query <<< "$line"
if [[ "${query[1]}" != "" ]]
then
echo "Thread ${query[1]} has been running query ${query[2]} ${query[0]}s"
if [[ "${query[0]}" -ge "${THRESHOLD}" ]]
then
echo "FU thread#${query[1]} and your query '''${query[2]}''' too!"
mysqladmin -u$USERNAME -p$PASSWORD kill ${query[1]}
fi
else
echo "no slow threads..."
fi
done <<< "$SLO_THREADS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment