Created
July 25, 2013 08:57
-
-
Save rahbirul/6078022 to your computer and use it in GitHub Desktop.
Calculate QPS (queries per second) from an Apache log.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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