diff --git a/docker/auth-bench/run-ab.sh b/docker/auth-bench/run-ab.sh index 6c92898..a805697 100644 --- a/docker/auth-bench/run-ab.sh +++ b/docker/auth-bench/run-ab.sh @@ -14,27 +14,34 @@ function run_apache_bench_and_check_ttfb { local requests=$REQUESTS local concurrency=$CONCURRENCY local log_file="/logs/authenticated.csv" - local ab_summary - local total_ttfb=0 - local ttfb=0 echo "URL,Average TTFB (ms),AB Mean Time per Request (ms)" | tee "$log_file" for url in "${urls[@]}"; do - total_ttfb=0 + local total_ttfb=0 + local ttfb=0 - ab_summary=$(ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" 2>&1 | grep "Time per request" | head -1) - ab_mean_time_per_request=$(echo "$ab_summary" | awk '{print $4}') + # Apache Bench + local ab_summary=$(ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" 2>&1 | grep "Time per request" | head -1) + local ab_mean_time_per_request=$(echo "$ab_summary" | awk '{print $4}' | awk '{printf "%.3f", $1}') + # TTFB for i in {1..5}; do ttfb=$(curl -o /dev/null -s -w "%{time_starttransfer}\n" -u "$username:$password" "$url") - total_ttfb=$(echo "$total_ttfb + $ttfb" | bc) + total_ttfb=$(echo "$total_ttfb + $ttfb" | bc -l) done - local mean_ttfb=$(echo "scale=3; $total_ttfb / 5 * 1000" | bc) + local mean_ttfb=$(echo "scale=3; ($total_ttfb / 5) * 1000" | bc) - echo "$url,$mean_ttfb,${ab_mean_time_per_request}" | tee -a "$log_file" + echo "$url,${mean_ttfb},${ab_mean_time_per_request}" | tee -a "$log_file" done } +function upload_to_hastebin { + local log_file="/logs/authenticated.csv" + local haste_url=$(curl -X POST -s -F "file=@${log_file}" https://haste.nixc.us/documents | awk -F '"' '{print "https://haste.nixc.us/"$4}') + echo "Logs uploaded to: $haste_url" +} + prepare_log_file run_apache_bench_and_check_ttfb +upload_to_hastebin \ No newline at end of file