Skip to content

Instantly share code, notes, and snippets.

@rahbirul
Created July 25, 2013 08:57
Show Gist options
  • Save rahbirul/6078022 to your computer and use it in GitHub Desktop.
Save rahbirul/6078022 to your computer and use it in GitHub Desktop.
Calculate QPS (queries per second) from an Apache log.
#!/bin/bash
#Naive calculation of QPS from Apache Log
#Usage: qps.sh /path/to/logfile
LOG=$1
START=$(head -n 1 $LOG | cut -d ' ' -f 4 | tr -d [)
END=$(tail -n 1 $LOG | cut -d ' ' -f 4 | tr -d [)
LINES=$(cat $LOG | wc -l)
DIFF=$(python -c "import sys,datetime; dt=lambda st: datetime.datetime.strptime(st, '%d/%b/%Y:%H:%M:%S'); print (dt(sys.argv[1]) - dt(sys.argv[2])).seconds" $END $START)
printf "scale=3\n$LINES/$DIFF\n"| bc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment