-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathautomate_perf.sh
executable file
·184 lines (159 loc) · 6.99 KB
/
automate_perf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
Help()
{
# Display Help
echo "Usage: automate_perf.sh [ -c | --capture-results-only ]
[ -f | --capture-from-time ]
[ -t | --capture-to-time ]
[ -h | --help ]"
echo "options:"
echo "-c | --capture-results-only Capture dashboards only, skip test execution."
echo "-f | --capture-from-time From time for capturing results"
echo "-t | --capture-to-time To time for capturing results"
echo "h Print this Help."
exit;
}
SHORT=c,f:,t:,h
LONG=capture-results-only,capture-from-time:,capture-to-time:,help
OPTS=$(getopt -a -n automate_perf.sh --options $SHORT --longoptions $LONG -- "$@")
VALID_ARGUMENTS=$# # Returns the count of arguments that are in short or long options
# Replace 'your_container_name' with the actual name of your Docker container
CONTAINER_NAME="load-k6-1"
# if [ "$VALID_ARGUMENTS" -eq 0 ]; then
# Help
# fi
eval set -- "$OPTS"
while :
do
case "$1" in
-c | --capture-results-only )
captureResultsOnly="true"
shift 1
;;
-f | --capture-from-time )
captureFromTime="$2"
shift 2
;;
-t | --capture-to-time )
captureToTime="$2"
shift 2
;;
-h | --help)
Help
;;
--)
shift;
break;
;;
*)
echo "ERROR: Unexpected option: $1"
echo
Help
;;
esac
done
if [ "$captureResultsOnly" ] && ([ -z "$captureFromTime" ] || [ -z "$captureToTime" ])
then
echo "ERROR: capture-from-time and capture-to-time should be provided in capture-result-only mode"
echo
Help
fi
source ./automate_perf.env
# define the list of dashboards
declare -a dashboards=(\
"dashboard-account-lookup-service" \
"Central%20Ledger%20DB" \
"Kafka%20Exporter%20Overview" \
"mojaloop-central-ledger" \
"Mojaloop%20-%20Central-Ledger%20-%20Performance%20Characterization" \
"Mojaloop%20-%20ML-API" \
"Docker%20Prometheus%20Monitoring" \
"NodeJS%20Application%20Dashboard" \
"Official%20k6%20Test%20Result" \
"MySQL%20Overview" \
"Supporting%20Services%20-%20Callback%20Hander%20Service" \
"Mojaloop%20-%20Quoting%20Service"
)
# # create a directory to store the results with date timestamp in the name, check if the directory exists
resultsSubDir="$(date +"%Y%m%d")"
if [ ! -d "results/$resultsSubDir/$K6_SCENARIO_NAME" ]; then
mkdir -p results/$resultsSubDir/$K6_SCENARIO_NAME
fi
if [ -z "$captureResultsOnly" ]
then
# store current time in a variable
echo "Start Time : $(date +"%T")"
startTestSeconds=$(date +"%s")
# get milliseconds
echo "Epoch Start Time : $(date +"%s%3N")"
startTestMilliseconds=$(date +"%s%3N")
if [ ! -d "results/$resultsSubDir/$K6_SCENARIO_NAME/logs" ]; then
mkdir -p results/$resultsSubDir/$K6_SCENARIO_NAME/logs
fi
env K6_SCRIPT_CONFIG_FILE_NAME=$K6_SCENARIO_CONFIG docker compose --project-name load -f docker-compose-load.yml up > results/$resultsSubDir/$K6_SCENARIO_NAME/logs/$CONTAINER_NAME.log
# Interval in seconds between status checks
CHECK_INTERVAL=1
while true; do
# Check if the container is running
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Container '${CONTAINER_NAME}' is running."
else
# Check if the container is stopped
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Container '${CONTAINER_NAME}' is stopped."
echo "End Time : $(date +"%T")"
endTestSeconds=$(date +"%s")
# get milliseconds
echo "Epoch End Time plus 2 minutes : $(date +"%s%3N")"
endTestMilliseconds=$(date -d '+2 minutes' +"%s%3N")
break
else
echo "Container '${CONTAINER_NAME}' not found."
break
fi
fi
# Wait for the specified interval before checking again
sleep $CHECK_INTERVAL
done
# Calculate the difference in seconds
difference=$((endTestSeconds - startTestSeconds))
s=$difference
((h=s/3600))
((m=s%3600/60))
((s=s%60))
printf "Time taken to run the test := %d:%02d:%02d\n" $h $m $s
# echo "Difference between timestamps: $difference seconds."
# Add sleep 10s for grafana to catchup with the metrics
sleep 10
else
startTestMilliseconds=$captureFromTime
endTestMilliseconds=$captureToTime
fi
if [ ! -d "results/$resultsSubDir/$K6_SCENARIO_NAME/images" ]; then
mkdir -p results/$resultsSubDir/$K6_SCENARIO_NAME/images
fi
# loop through the array
for dashboard in "${dashboards[@]}"
do
echo "$dashboard"
dashboard_string=$(echo $dashboard | sed 's/%20/ /g' | tr -d ' ')
# printf -v dashboard_string "%b" "${dashboard//\%/\\x}"
echo "$dashboard_string"
dashboardUrl=$(curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/api/search?query=$dashboard" | jq -r '.[].url')
#check if dashboard is NodeJSApplicationDashboard
if [[ $dashboard_string == *"NodeJSApplicationDashboard"* ]]; then
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=5000&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds&var-prefix=moja_als&var-instance=All&var-serviceName=All&var-podName=All" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string-moja_als.png
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=5000&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds&var-prefix=moja_cl&var-instance=All&var-serviceName=All&var-podName=All" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string-moja_cl.png
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=5000&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds&var-prefix=moja_ml&var-instance=All&var-serviceName=All&var-podName=All" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string-moja_ml.png
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=5000&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds&var-prefix=cbs&var-instance=All&var-serviceName=All&var-podName=All" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string-cbs.png
elif [[ $dashboard_string == *"MySQLOverview"* ]]; then
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=6500&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string.png
else
curl "http://$GRAFANA_USERNAME:$GRAFANA_PASSWORD@$GRAFANA_HOSTNAME:$GRAFANA_PORT/render$dashboardUrl?height=5000&width=2000&from=$startTestMilliseconds&to=$endTestMilliseconds" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/images/$dashboard_string.png
fi
done
# Generate an empty README
echo "# Scenario ${K6_SCENARIO_NAME}: ${K6_SCENARIO_DESCRIPTION}
Params: &from=${startTestMilliseconds}&to=${endTestMilliseconds}
" > ./results/$resultsSubDir/$K6_SCENARIO_NAME/README.md
echo "Epoch &from=${startTestMilliseconds}&to=${endTestMilliseconds}"