#!/bin/bash # # Activate Bash Strict Mode set -euo pipefail main() { { echo -e "URL\tRuns\tStDev\tMin (ms)\tAvg (ms)\tMax (ms)" for url in ${@:2}; do get_statistics $url $1 done } #| column -s $'\t' -t } get_statistics() { # Initialice the variables local min=1000000000 local max=0 local dur=0 local durQ=0 local spin=0 local spiner=('-' '\' '|' '/') echo -ne "$1\t " # repeat for the defined counts the url calling for i in $(seq 1 $2); do echo -ne "\b${spiner[$spin]}" spin=$(( (spin+1) % 4 )) local gp=$(($(get_posts $1)/1000000)) # from ns to ms if [[ $gp -gt $max ]] then max=$gp fi if [[ $gp -lt $min ]] then min=$gp fi dur=$(( $dur + $gp )) durQ=$(( $durQ + $(($gp * $gp)) )) done local avg=$(($dur/$2)) local avgPow=$(($avg * $avg)) local stdev=$( echo "sqrt(($durQ / $2) - $avgPow)" | bc ) # output the statistic values echo -e "\b$2\t$stdev\t$min\t$avg\t$max" } get_posts() { # Call the url with measure time local start=$(date +%s%N) curl --silent --show-error $1 > /dev/null local stop=$(date +%s%N) local dur=$(($stop-$start)) echo $dur } print_process() { ps -C java --no-headers --format "pid %cpu %mem rss pss cmd" |\ awk 'BEGIN { printf "%6s %5s %4s %13s %13s %-50s\n", "pid", "%cpu", "%mem", "rss Mb", "pss Mb", "cmd"} {hr=$4/1024; hp=$5/1024; printf("%6i %5.1f %4.1f %13.2f %13.2f %s\n", $1, $2, $3,hr, hp, $6) }' } # the main domain #hostname="https://briefedition.wedekind.h-da.de" hostname="http://localhost:8080/WedekindJSF-1.0.0" # the Array of the Urls url_arr=( "$hostname/index.xhtml" "$hostname/view/document/list.xhtml" #"$hostname/view/correspondent/list.xhtml" #"$hostname/view/person/list.xhtml" ) print_process echo "" # Execute all the URLs for 10 rounds main 10 ${url_arr[@]} echo "" print_process