Update docker/bench/run-ab.sh

This commit is contained in:
colin 2024-02-07 11:06:50 +00:00
parent 9734935762
commit 7ee72e7590
1 changed files with 29 additions and 12 deletions

View File

@ -30,8 +30,8 @@ upload_to_hastebin() {
}
parse_to_csv() {
local input=$log_file
local output=/log/scan.csv
local input="$1"
local output="$2"
local output_dir=$(dirname "$output")
# Ensure the output directory exists
@ -45,18 +45,35 @@ parse_to_csv() {
exit 1
fi
: > "$output" # Clear output file before appending
# Write CSV header
echo "URL,Time (ms),Status,Test Type" > "$output"
grep -Eo 'https?://[^ ]+' "$input" | sort -u | while read -r url; do
local ttfb_line=$(grep -m 1 "$url" "$input" | grep 'TTFB test passed' | awk -F'Mean TTFB: ' '{print $2}')
local ab_line=$(grep -m 1 "$url" "$input" | grep 'ApacheBench test passed' | awk -F'Average time: ' '{print $2}')
local ttfb_test=${ttfb_line%ms.*}
local ab_test=${ab_line% milliseconds.*}
if [[ -n "$ttfb_test" || -n "$ab_test" ]]; then
if [[ -z "$ttfb_test" ]]; then ttfb_test="N/A"; fi
if [[ -z "$ab_test" ]]; then ab_test="N/A"; fi
echo "$url,$ttfb_test,$ab_test" >> "$output"
grep -E 'TTFB test|ApacheBench test' "$input" | while IFS= read -r line; do
local url=$(echo "$line" | grep -Eo 'https?://[^ ]+')
local time
local status
local test_type
if [[ "$line" =~ "TTFB test passed" ]]; then
time=$(echo "$line" | awk -F'Mean TTFB: ' '{print $2}' | awk '{print $1}')
status="pass"
test_type="TTFB"
elif [[ "$line" =~ "ApacheBench test passed" ]]; then
time=$(echo "$line" | awk -F'Average time: ' '{print $2}' | awk '{print $1}')
status="pass"
test_type="AB"
elif [[ "$line" =~ "TTFB test failed" ]]; then
time="N/A" # Indicate not applicable or failed to obtain time
status="fail"
test_type="TTFB"
elif [[ "$line" =~ "ApacheBench test failed" ]]; then
time="N/A" # Indicate not applicable or failed to obtain time
status="fail"
test_type="AB"
fi
# Output to CSV
echo "$url,$time,$status,$test_type" >> "$output"
done
}