Last active
June 16, 2020 16:53
-
-
Save aramse/27798a0b793fb6c63314c84072d1faa8 to your computer and use it in GitHub Desktop.
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
function check_thresholds(){ | |
FILE=$1 | |
THRESHOLDS=$2 | |
failed=0 | |
if ! [ -z "$THRESHOLDS" ]; then | |
IFS="," | |
for pair in $THRESHOLDS; do | |
echo "checking if $pair ..." | |
echo $pair | grep "<" > /dev/null && use_lt=1 || use_lt=0 | |
[ $use_lt -eq 1 ] && delim="<" || delim=">" | |
key=$(echo $pair | cut -d $delim -f 1) # column name | |
t_val=$(echo $pair | cut -d $delim -f 2) # threshold value | |
val=$(cat $FILE | csvcut -c "$key" | tail -1) # actual value | |
[ "$val" == "N/A" ] && echo "ERROR: value for $key is N/A" && failed=1 && continue | |
val=${val/\.*} # convert floats to ints (round down) | |
if [ $use_lt -eq 1 ]; then | |
[ $val -lt $t_val ] || { echo "FAILED: value $val for field $key was expected to be less than threshold of $t_val" && failed=1; } | |
else | |
[ $val -gt $t_val ] || { echo "FAILED: value $val for field $key was expected to be greater than threshold of $t_val" && failed=1; } | |
fi | |
done | |
fi | |
return $failed | |
} | |
check_thresholds stats.csv "Requests/s>10,98%<20" | |
check_thresholds stats2.csv "Requests/s>10,98%<20" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment