Last active
August 29, 2015 13:55
-
-
Save pgwillia/8717304 to your computer and use it in GitHub Desktop.
calculates average qtime and counts errors from a Tomcat log file
This file contains hidden or 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 | |
| # calculates average qtime and counts errors from a Tomcat log file ($CATALINA_HOME/logs/catalina.out) | |
| if [ -z "$1" ] ; then | |
| echo "requires a Tomcat log path" | |
| exit 1 | |
| fi | |
| grep -v "^map entry" $1 | paste - - | | |
| awk -v start="$2" -v end="$3" 'BEGIN{ | |
| if( start == "" ) { | |
| print "you can specify the start of the range by adding a second argument in the form \"Jan 30, 2014 8:13:20 AM\"" | |
| print "using default, the last five minutes" | |
| cmd="date \"+%Y/%m/%d %T\" --date \"now -5 mins\""; | |
| cmd | getline from; | |
| } else { | |
| cmd="date \"+%Y/%m/%d %T\" --d \"" start "\""; | |
| cmd | getline from; | |
| } | |
| print "computing entries after " from "\n"; | |
| if( end == "" ) { | |
| print "you can specify the end of the range by adding a third argument in the form \"Jan 30, 2014 8:18:20 AM\"" | |
| print "using default, now" | |
| cmd="date \"+%Y/%m/%d %T\" --date \"now\""; | |
| cmd | getline to; | |
| } else { | |
| cmd="date \"+%Y/%m/%d %T\" --d \"" end "\""; | |
| cmd | getline to; | |
| } | |
| print "computing entries before " to "\n"; | |
| } | |
| { | |
| tmp=$1 " " $2 " " $3 " " $4 " " $5; | |
| cmd="date \"+%Y/%m/%d %T\" --d \"" tmp "\""; | |
| cmd | getline date; | |
| if(date>=from && date<=to) { | |
| if(min==""){ | |
| min=max=$11 | |
| }; | |
| if($11>max) { | |
| max=$11 | |
| }; | |
| if($11< min) { | |
| min=$11 | |
| }; | |
| total+=$11; | |
| count+=1 | |
| errors+=$10 | |
| } | |
| } END { | |
| if(0<count) { | |
| print "avg query time: " total/count "\nmin query time: " min "\nmax query time: " max "\nerrors: " errors "\ntotal queries: " count | |
| } else { | |
| print "no queries in that interval" | |
| } | |
| }' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage for summary of last five minutes:
./benchmark.sh catalina.out
usage for summary since Jan 30, 2014 8:13:19 AM
./benchmark.sh catalina.out "Jan 30, 2014 8:13:19 AM"
usage for summary between Jan 30, 2014 8:13:19 AM and Jan 30, 2014 8:43:19 AM
./benchmark.sh catalina.out "Jan 30, 2014 8:13:19 AM" "Jan 30, 2014 8:43:19 AM"
to get input for an arbitrary interval (example 10 minutes)
$ date "+%b %d, %Y %r" --date "now -10 mins"
Jan 30, 2014 12:41:09 PM