-
Notifications
You must be signed in to change notification settings - Fork 0
/
testable-kpi-monitor.sh
executable file
·29 lines (23 loc) · 1.28 KB
/
testable-kpi-monitor.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
#!/bin/bash
execution_id=$1
echo "[$(date)] Waiting for execution to complete (view online at https://a.testable.io/results/$execution_id)"
while [ $(curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id | jq -r ".completed") = "false" ]; do
echo -n "."
sleep 5
done
details=$(curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id)
latency=$(echo "$details" | jq -r '.summary.metrics | .[] | select(.metricDef=="firstReceivedMs") | .metricValueMap.p50')
total_outcomes=$(echo "$details" | jq -r '.summary.metrics | .[] | select(.metricDef=="outcome") | .metricValue')
success_outcomes=$(echo "$details" | jq -r '.summary.metrics | .[] | select(.metricDef=="outcome") | .metricValueMap.success')
let "success_rate=100*$success_outcomes/$total_outcomes"
echo -e "\n[$(date)] Median Response Time: ${latency}ms"
echo "[$(date)] Success Rate: ${success_rate}%"
epoch=$(date +"%s")
echo "[$(date)] Storing CSV results at results-$epoch.csv"
curl -H "X-Testable-Key:$TESTABLE_KEY" --silent https://api.testable.io/executions/$execution_id/results.csv > results-$epoch.csv
if [ $(echo "$details" | jq -r ".success") = "false" ]; then
echo -e "[$(date)] Test FAILED"
exit 1
else
echo -e "[$(date)] Test SUCCESS"
fi