Skip to content

Instantly share code, notes, and snippets.

@dcampano
Created April 15, 2012 14:14
Show Gist options
  • Save dcampano/2393069 to your computer and use it in GitHub Desktop.
Save dcampano/2393069 to your computer and use it in GitHub Desktop.
Parse a mysql slow query log and show how many times queries over a certain threshold happened
# Script used to quickly get a glance of how many queries since a certain time period were longer than X seconds
# Customize these 2 parameters
STARTDATE="120413" # 2 Digit Year, 2 Digit Month, 2 Digit Day
QUERYTIME=3.0
# Runs the commands and prints out Query_time lines
FIRST=`grep -n -m 1 "# Time: $STARTDATE" /var/log/mysql-slow.log | cut -d : -f 1`; TOTAL=`wc -l /var/log/mysql-slow.log | cut -d ' ' -f 1`; tail -n `echo "$TOTAL-$FIRST" | bc` /var/log/mysql-slow.log | grep Query_time | awk -v time="$QUERYTIME" '$3 > time {print; }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment