Last active
July 20, 2021 09:11
-
-
Save roblogic/da238766f5e645ddfb7290b06b1f80f0 to your computer and use it in GitHub Desktop.
jstats2 - Parse Jmeter output (csv), compute statistics about the test execution and response times.
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 | |
# Parse jmeter output and get various stats | |
# Hat-tip to 'stig', https://git.io/vFmeI | |
set -e # Exit immediately on error | |
# set -x # Debug | |
usage="jstats2 <jmeter-csv-output-file>" | |
[ $1 ] || { echo "$usage" ; exit 1 ; } | |
JFILE=$1 | |
# Show timestamp info | |
UT1=$(sed -n '2p' $JFILE | cut -c -10) | |
UT2=$(tail -1 $JFILE | cut -c -10) | |
DUR=$(( $UT2 - $UT1 )) | |
echo -e "\n\033[1m --test run details--\033[0m" | |
echo " started $(date --date="@$UT1" +"%y%m%d-%H%M%S")" | |
echo " stopped $(date --date="@$UT2" +"%y%m%d-%H%M%S")" | |
echo "duration $DUR sec" | |
# Create temp file of elapsed times (column 2 of the output csv) | |
WORK=$(mktemp /tmp/$(basename $0).XXXXX) || exit 1 | |
cut -d, -f2 $JFILE | grep . | grep -v "elapsed" | sort -n > $WORK | |
echo "tmp-file $WORK" | |
N=$(wc -l < $WORK) | |
echo " count n $N" | |
echo "avg-load $(( $N / $DUR )) tps" | |
# fail count | |
FC=$(awk -F, '$8 ~ /false/{print}' $JFILE | wc -l) | |
FP=$(echo "scale=6; 100 * $FC / $N" | bc | awk '{printf "%3.3f", $0}') | |
echo " fails $FC ($FP %)" | |
# success count | |
SC=$(( $N - $FC )) | |
SP=$(echo "scale=6; 100 * $SC / $N" | bc | awk '{printf "%3.3f", $0}') | |
echo " success $SC ($SP %)" | |
echo -e "\n\033[1m --response stats (ms)--\033[0m" | |
P50=$(dc -e "$N 2 / p") | |
P90=$(dc -e "$N 9 * 10 / p") | |
P95=$(dc -e "$N 95 * 100 / p") | |
P99=$(dc -e "$N 99 * 100 / p") | |
echo " median $(awk "FNR==$P50" $WORK)" | |
echo " p90 $(awk "FNR==$P90" $WORK)" | |
echo " p95 $(awk "FNR==$P95" $WORK)" | |
echo " p99 $(awk "FNR==$P99" $WORK)" | |
echo -e " mean \u03BC $(awk '{sum+=$1}END{if (NR>0) print sum/NR}' $WORK)" | |
echo -e "stddev \u03C3 $(awk '{x+=$0;y+=$0^2}END{print sqrt(y/NR-(x/NR)^2)}' $WORK)" | |
echo " min $(awk "FNR==1" $WORK)" | |
echo " max $(awk "END{print}" $WORK)" |
Next step: graphical analysis with gnuplot
A more generic version that computes stats for any data on stdin: istats
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output