bachelor-thesis/chapters/thesis/appendix04_calling_script.sh

220 lines
8.5 KiB
Bash
Raw Normal View History

2024-08-16 22:13:36 +02:00
#!/bin/bash
payara_path="/opt/docker/payara"
postgres_path="/var/lib/postgres"
postgres_path="/opt/docker"
postgres_data_path="$postgres_path/data"
postgres_log_path=$postgres_data_path/log
payara_config="$payara_path/config/domain.xml"
domain_log="$payara_path/logs/server.log"
script_path="/opt/docker/timing.sh"
pgbadger_out="/opt/docker/pgreport"
report_postfix=""
2024-08-19 21:00:19 +02:00
report_postno=""
2024-09-11 19:34:36 +02:00
report_postmax="5"
2024-08-16 22:13:36 +02:00
docker_name=dcpgbatch
COMPOSE_FILE=/opt/docker/docker-compose.yaml
gflog() {
echo "follow the log: $domain_log"
tail -f $domain_log
}
2024-09-11 19:34:36 +02:00
gflogrm() {
echo "remove the log: $domain_log"
rm "$domain_log"
}
2024-08-16 22:13:36 +02:00
gfconf() {
nvim "$payara_config"
}
gfscript() {
2024-09-11 19:34:36 +02:00
gflogcount=$(cat "$domain_log" | wc -l)
2024-08-16 22:13:36 +02:00
outPath=$pgbadger_out$report_postfix/bash.out
touch "$outPath"
2024-09-11 19:34:36 +02:00
echo "" >>"$outPath"
2024-08-16 22:13:36 +02:00
echo "============================================================" >>"$outPath"
2024-09-11 19:34:36 +02:00
echo "calling number $report_postno / $report_postmax" >>"$outPath"
echo "" >>"$outPath"
2024-08-16 22:13:36 +02:00
bash $script_path | tee -a "$outPath"
2024-09-11 19:34:36 +02:00
gflastlog=$(cat "$domain_log" | wc -l)
gfcnt=$(($gflastlog - $gflogcount))
printf "\n%-20s %+5s %+9s %+9s %+9s %+9s\n" "function" "Runs" "Min (ms)" "Avg (ms)" "Max (ms)" "1st (ms)" >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-create \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-create-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-build \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-buildr-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-loadData \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-loaddt-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-loadDataMap \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-loaddm-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-renderData \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-rdrdat-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-renderLoad \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-rdrlst-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
tail -$gfcnt $domain_log | awk '/PerformanceCounter-render \/view/ { print $3 }' | awk 'BEGIN {min=500;max=0} {sum += $1; cnt += 1}; first == "" { first = $1 }; min > $1 { min = $1 } max < $1 { max = $1 } END { if (cnt < 1) {cnt = -1}; printf("%-20s %5i %9.3f %9.3f %9.3f %9.3f\n", "view-render-list", cnt, min, sum/cnt, max, first) }' >>"$outPath"
2024-08-16 22:13:36 +02:00
}
pginit() {
sudo chmod g+x $postgres_path
sudo chmod g+x $postgres_data_path
sudo chmod g+rx $postgres_log_path
}
pglogls() {
echo "show postgresql logfiles"
ls $postgres_log_path/ -lhtc
}
pglogrm() {
cnt=${1:-10}
cntTail=$(($cnt + 1))
echo "remove old postgresql logfiles from $(ls $postgres_log_path/ -tc | wc -l) until $cnt (~${cnt}00 MB) $cntTail"
ls $postgres_log_path/ -tc | tail -n +$cntTail | xargs -r -I{} sudo rm "$postgres_log_path/{}"
}
pglog() {
pg_log=$(ls $postgres_log_path/ -tc --ignore '*log' | head -n 1)
echo "follow the log: $postgres_log_path/$pg_log"
tail -n 3 -f $postgres_log_path/$pg_log
}
pgconf() {
sudo nvim "${postgres_path}/postgresql.conf"
}
pgrp() {
mkdir -p $pgbadger_out$report_postfix
2024-08-19 21:00:19 +02:00
mkdir -p $pgbadger_out$report_postfix$report_postno
2024-08-16 22:13:36 +02:00
outPath=$pgbadger_out$report_postfix/bash.out
touch "$outPath"
echo "" >>"$outPath"
2024-08-19 21:00:19 +02:00
pgbadger -X -I -f jsonlog -j 10 -O $pgbadger_out$report_postfix$report_postno $postgres_log_path/postgresql-*.json 2>&1 | tee -a "$outPath"
2024-08-16 22:13:36 +02:00
}
pgrpres() {
2024-08-21 00:30:20 +02:00
if [[ "$report_postfix" == "" ]]; then
2024-08-19 21:00:19 +02:00
rm -R $pgbadger_out
else
rm -R $pgbadger_out$report_postfix*
fi
2024-08-16 22:13:36 +02:00
}
2024-09-11 19:34:36 +02:00
pgrpout() {
echo "Show bash output"
outPath=$pgbadger_out$report_postfix/bash.out
cat "$outPath"
}
2024-08-16 22:13:36 +02:00
dccreate() {
sudo docker compose -f $COMPOSE_FILE create --force-recreate
}
2024-09-11 19:34:36 +02:00
dcconf() {
nvim $COMPOSE_FILE
}
2024-08-16 22:13:36 +02:00
dcstart() {
sudo docker compose -f $COMPOSE_FILE start
sleep 2
pginit
}
dcstop() {
sudo docker compose -f $COMPOSE_FILE stop
}
2024-08-21 23:44:10 +02:00
dcres() {
sudo docker compose -f $COMPOSE_FILE down
}
2024-08-16 22:13:36 +02:00
dcstats() {
sudo docker stats
}
2024-09-11 19:34:36 +02:00
meascall() {
gfscript
pgrp
pglogrm
}
measrun() {
for i in $(seq 1 $report_postmax); do
report_postno=$i
meascall
done
}
2024-08-16 22:13:36 +02:00
for name in "$@"; do
case $name in
2024-08-19 21:00:19 +02:00
-rppf=*) report_postfix="${name#*=}" ;;
-rppn=*) report_postno="${name#*=}" ;;
2024-09-11 19:34:36 +02:00
-rppm=*) report_postmax="${name#*=}" ;;
2024-08-16 22:13:36 +02:00
gflog) gflog ;;
2024-09-11 19:34:36 +02:00
gflogrm) gflogrm ;;
2024-08-16 22:13:36 +02:00
gfconf) gfconf ;;
gfscript) gfscript ;;
2024-08-19 21:00:19 +02:00
gfrestart) pgrpinit ;;
2024-08-16 22:13:36 +02:00
pginit) pginit ;;
pglogls) pglogls ;;
pglogrm) pglogrm ;;
pglog) pglog ;;
pgconf) pgconf ;;
pgrestart) pgrestart ;;
pgrp) pgrp ;;
pgrpres) pgrpres ;;
2024-09-11 19:34:36 +02:00
pgrpout) pgrpout ;;
2024-08-16 22:13:36 +02:00
dcinit) dccreate ;;
2024-09-11 19:34:36 +02:00
dcconf) dcconf ;;
2024-08-16 22:13:36 +02:00
dcstart) dcstart ;;
dcstop) dcstop ;;
2024-08-21 23:44:10 +02:00
dcres) dcres ;;
2024-08-16 22:13:36 +02:00
dcstats) dcstats ;;
measinit)
2024-08-19 21:00:19 +02:00
pginit
2024-08-16 22:13:36 +02:00
pgrpres
pglogrm 0
2024-09-11 19:34:36 +02:00
gflogrm
2024-08-16 22:13:36 +02:00
dccreate
dcstart
;;
measres)
dcstop
pgrpres
pglogrm 0
2024-09-11 19:34:36 +02:00
gflogrm
2024-08-16 22:13:36 +02:00
dcstart
pgrp
pglogrm
;;
2024-09-11 19:34:36 +02:00
meascall) meascall ;;
measrun) measrun ;;
2024-08-16 22:13:36 +02:00
help)
echo "CALLING: $0 <function> [ <function>]"
echo "The overview of the functions of this script."
echo "It is allowed to enter multiple functions in one execute,"
echo "that would be called serialized."
echo "ATTENTION: parameter must be defined in front of the commands!"
echo ""
echo "*** parameter ***"
2024-08-19 21:00:19 +02:00
echo " -rppf=<val> Postfix name for the report-folder (used by gfscript, pgrp, pgrpres, measres, meascall)"
echo " -rppn=<val> Postfix number for the report-folder (used by pgrp, measres, meascall)"
2024-09-11 19:34:36 +02:00
echo " -rppm=<val> Count of calling meascall (used by measrun)"
2024-08-16 22:13:36 +02:00
echo ""
echo "*** glassfish ***"
echo " gflog Show and follow the log of the glassfish server with $domain_name"
2024-09-11 19:34:36 +02:00
echo " gflogrm Remove the log file of the glassfish server with $domain_name"
2024-08-16 22:13:36 +02:00
echo " gfconf Open the configuration file from glassfish server"
echo " gfscript Calls the testscript for the website"
echo ""
echo "*** postgresql ***"
echo " pginit Initialize the folder for postgresql log-folder"
echo " pglogls Show the current content of the log-folder from postgresql"
echo " pglogrm Clean the log-folder from postgresql, the newest 20 files are sill available"
echo " pglog Show and follow the last log from postgresql"
echo " pgconf Open the configuration file from postgresql"
echo " pgrestart Restart the postgresql"
echo " pgrp Generate the pgbadger report from postgresql log files"
2024-09-11 19:34:36 +02:00
echo " pgrpout Show the saved output of the bash scripts"
2024-08-16 22:13:36 +02:00
echo " pgrpres Resetet the output of pgbadger"
echo ""
echo "*** docker ***"
2024-09-11 19:34:36 +02:00
echo " dcinit Create the both docker container"
echo " dcconf Open the configuration file for the docker container"
echo " dcstart Start the both docker container"
echo " dcstop Stop the both docker container stoppen"
echo " dcres Stop and remote the both docker container"
echo " dcstats Show the docker live statistik"
2024-08-16 22:13:36 +02:00
echo ""
echo "*** combine cmds ***"
echo " measinit Initialize everthing after start"
echo " measres reset data for new measuring"
echo " meascall execute one measure"
2024-09-11 19:34:36 +02:00
echo " measrun execute <rppm> calls of measure (default: 5 runs)"
2024-08-16 22:13:36 +02:00
;;
*)
echo >&2 "Invalid option $name"
exit 1
;;
esac
done