From 71be6834f92681cb5a667e8dca626c6d69db0fe0 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 22 Feb 2024 12:52:02 +0000 Subject: [PATCH] trying to add more log info. --- docker/auth-bench/run-ab.sh | 89 +++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/docker/auth-bench/run-ab.sh b/docker/auth-bench/run-ab.sh index bea1966..46fd8a9 100644 --- a/docker/auth-bench/run-ab.sh +++ b/docker/auth-bench/run-ab.sh @@ -1,5 +1,47 @@ #!/bin/bash +function test_urls { + local urls=(${URLS//,/ }) + local username=$USERNAME + local password=$PASSWORD + for url in "${urls[@]}"; do + curl -u "$username:$password" "$url" + done +} + +function run_apache_bench { + local urls=(${URLS//,/ }) + local username=$USERNAME + local password=$PASSWORD + local requests=$REQUESTS + local concurrency=$CONCURRENCY + local log_file="/logs/authenticated.log" + for url in "${urls[@]}"; do + ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" | tee -a "$log_file" + done +} + +function check_ttfb_and_log { + local urls=(${URLS//,/ }) + local username=$USERNAME + local password=$PASSWORD + local log_file="/logs/authenticated.csv" + local total_ttfb sum_ttfb mean_ttfb http_code + echo "URL,Username,HTTP Code,Mean TTFB" > "$log_file" + for url in "${urls[@]}"; do + total_ttfb=0 + for i in {1..5}; do + response=$(curl -o /dev/null -s -w "%{http_code},%{time_starttransfer}\n" -u "$username:$password" "$url") + http_code=$(echo "$response" | cut -d',' -f1) + ttfb=$(echo "$response" | cut -d',' -f2) + total_ttfb=$(echo "$total_ttfb + $ttfb" | bc) + done + sum_ttfb=$total_ttfb + mean_ttfb=$(echo "scale=3; $sum_ttfb / 5" | bc) + echo "$url,$username,$http_code,$mean_ttfb" | tee -a "$log_file" + done +} + function prepare_log_file { local log_file="/logs/authenticated.csv" > "$log_file" @@ -7,47 +49,8 @@ function prepare_log_file { touch "$log_file" } -function run_apache_bench_and_check_ttfb { - local urls=(${URLS//,/ }) - local username=$USERNAME - local password=$PASSWORD - local requests=$REQUESTS - local concurrency=$CONCURRENCY - local log_file="/logs/authenticated.csv" - - echo "URL,Average TTFB (ms),AB Mean Time per Request (ms)" | tee "$log_file" - - for url in "${urls[@]}"; do - local total_ttfb=0 - local ttfb=0 - - # 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 -l) - done - local mean_ttfb=$(echo "scale=3; ($total_ttfb / 5) * 1000" | bc) - - 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 response=$(curl -X POST -s --data-binary @"${log_file}" https://haste.nixc.us/documents) - local key=$(echo $response | awk -F '"' '{print $4}') - if [ ! -z "$key" ]; then - local haste_url="https://haste.nixc.us/$key" - echo "Logs uploaded to: $haste_url" - else - echo "Failed to upload logs to Hastebin." - fi -} - prepare_log_file -run_apache_bench_and_check_ttfb -upload_to_hastebin \ No newline at end of file + +test_urls +run_apache_bench +check_ttfb_and_log