Update docker/auth-bench/run-ab.sh
This commit is contained in:
		
							parent
							
								
									a3decd963a
								
							
						
					
					
						commit
						53fe1d5a20
					
				|  | @ -1,53 +1,50 @@ | ||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 | function run_apache_bench_and_check_ttfb { | ||||||
| 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 urls=(${URLS//,/ }) | ||||||
|   local username=$USERNAME |   local username=$USERNAME | ||||||
|   local password=$PASSWORD |   local password=$PASSWORD | ||||||
|   local requests=$REQUESTS |   local requests=$REQUESTS | ||||||
|   local concurrency=$CONCURRENCY |   local concurrency=$CONCURRENCY | ||||||
|   local log_file="/logs/authenticated.log" |   local log_file="/logs/authenticated.csv" | ||||||
|   for url in "${urls[@]}"; do |   local ab_summary | ||||||
|     ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" | tee -a "$log_file" |   local total_ttfb=0 | ||||||
|   done |   local ttfb=0 | ||||||
| } |    | ||||||
|  |   echo "URL, Average TTFB, AB Mean Time per Request" | tee "$log_file" | ||||||
|    |    | ||||||
| function check_ttfb_and_log { |  | ||||||
|   local urls=(${URLS//,/ }) |  | ||||||
|   local username=$USERNAME |  | ||||||
|   local password=$PASSWORD |  | ||||||
|   local log_file="/logs/authenticated.log" |  | ||||||
|   local total_ttfb sum_ttfb mean_ttfb |  | ||||||
|   for url in "${urls[@]}"; do |   for url in "${urls[@]}"; do | ||||||
|     total_ttfb=0 |     total_ttfb=0 # Reset total TTFB for each URL | ||||||
|  |      | ||||||
|  |     # Apache Bench part | ||||||
|  |     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 " " $5}') | ||||||
|  |      | ||||||
|  |     # TTFB part | ||||||
|     for i in {1..5}; do |     for i in {1..5}; do | ||||||
|       ttfb=$(curl -o /dev/null -s -w "%{time_starttransfer}\n" -u "$username:$password" "$url") |       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) | ||||||
|     done |     done | ||||||
|     sum_ttfb=$total_ttfb |     local mean_ttfb=$(echo "scale=3; $total_ttfb / 5" | bc) | ||||||
|     mean_ttfb=$(echo "scale=3; $sum_ttfb / 5" | bc) |      | ||||||
|     echo "$url TTFB Mean: $mean_ttfb seconds" | tee -a "$log_file" |     # Combine and log | ||||||
|  |     echo "$url, $mean_ttfb, $ab_mean_time_per_request" | tee -a "$log_file" | ||||||
|   done |   done | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | # Define your functions here | ||||||
| function prepare_log_file { | function prepare_log_file { | ||||||
|   local log_file="/logs/authenticated.log" |   local log_file="/logs/authenticated.csv" | ||||||
|   > "$log_file" |   > "$log_file" # Clear the contents of the existing log file, if any | ||||||
|   mkdir -p $(dirname "$log_file") |   mkdir -p $(dirname "$log_file") # Ensure the directory exists | ||||||
|   touch "$log_file" |   touch "$log_file" # Create the file if it doesn't exist | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function run_apache_bench_and_check_ttfb { | ||||||
|  |   # Function definition as provided before | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | # Prepare the log file | ||||||
| prepare_log_file | prepare_log_file | ||||||
| 
 | 
 | ||||||
| test_urls | # Run Apache Bench and check TTFB for URLs | ||||||
| run_apache_bench | run_apache_bench_and_check_ttfb | ||||||
| check_ttfb_and_log |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 colin
						colin