Update docker/auth-bench/run-ab.sh
This commit is contained in:
parent
dd867b767d
commit
4cc9f633b5
|
@ -1,51 +1,5 @@
|
|||
#!/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,Mean TTFB,HTTP Code" > "$log_file"
|
||||
|
||||
for url in "${urls[@]}"; do
|
||||
total_ttfb=0
|
||||
for i in {1..5}; do
|
||||
response=$(curl -o /dev/null -s -w "%{time_starttransfer},%{http_code}\n" -u "$username:$password" "$url")
|
||||
IFS=',' read -r ttfb http_code <<< "$response"
|
||||
total_ttfb=$(echo "$total_ttfb + $ttfb" | bc)
|
||||
done
|
||||
sum_ttfb=$total_ttfb
|
||||
mean_ttfb=$(echo "scale=3; $sum_ttfb / 5" | bc)
|
||||
echo "$url,$username,$mean_ttfb,$http_code" >> "$log_file"
|
||||
done
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
function prepare_log_file {
|
||||
local log_file="/logs/authenticated.csv"
|
||||
> "$log_file"
|
||||
|
@ -53,7 +7,48 @@ 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,Username,HTTP Code,Average TTFB (ms),AB Mean Time per Request (ms)" | tee "$log_file"
|
||||
|
||||
for url in "${urls[@]}"; do
|
||||
local total_ttfb=0
|
||||
local ttfb=0
|
||||
local http_code=$(curl -o /dev/null -s -w "%{http_code}" -u "$username:$password" "$url")
|
||||
|
||||
# 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,$username,$http_code,${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
|
||||
test_urls
|
||||
run_apache_bench
|
||||
check_ttfb_and_log
|
||||
run_apache_bench_and_check_ttfb
|
||||
upload_to_hastebin
|
||||
|
|
Loading…
Reference in New Issue