-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwait_requests
executable file
·56 lines (42 loc) · 2.25 KB
/
wait_requests
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
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status
# Check if the output file parameter is specified
if [ -z "$1" ]; then
echo "Error: No JSON output file specified."
echo "Usage: $0 <output_file>"
exit 1
fi
# Check if AWS profile is set
if [ -z "$AWS_PROFILE" ]; then
echo "Error: AWS_PROFILE environment variable is not set."
exit 1
fi
# Get the output file from the first script argument
output_file=$1
echo "Monitoring CloudWatch metrics for new datapoints..."
# Check if localstack-main container is running
if [ -z "$(docker ps -q -f name=localstack-main)" ]; then
echo "Error: LocalStack container is not running."
exit 1
fi
# Get the start time of the localstack container
start_time=$(docker inspect -f '{{.State.StartedAt}}' localstack-main | sed 's/\.[0-9]*Z//' | xargs -I{} date -u -j -f '%Y-%m-%dT%H:%M:%S' {} +'%Y-%m-%dT%H:%M:%S')
end_time=$(date -u +'%Y-%m-%dT%H:%M:%S')
# Initial run to get the current number of datapoints
current_datapoints=$(aws cloudwatch get-metric-statistics --namespace ServerlessDataProcessingPipeline/Latencies --metric-name Latency --start-time $start_time --end-time $end_time --period 1 --statistics SampleCount | jq '[.Datapoints[].SampleCount] | add')
while true; do
sleep 5 # Wait for 5 seconds
end_time=$(date -u +'%Y-%m-%dT%H:%M:%S')
# Get the number of datapoints again
new_datapoints=$(aws cloudwatch get-metric-statistics --namespace ServerlessDataProcessingPipeline/Latencies --metric-name Latency --start-time $start_time --end-time $end_time --period 1 --statistics SampleCount | jq '[.Datapoints[].SampleCount] | add')
# If the number of datapoints hasn't changed, break the loop
if [ "$new_datapoints" -eq "$current_datapoints" ]; then
echo "No new datapoints added. Exiting."
break
fi
# Update the current number of datapoints
current_datapoints=$new_datapoints
done
# Export the datapoints to the output file in JSON format
echo "Exporting CloudWatch metrics to $output_file..."
aws cloudwatch get-metric-statistics --namespace ServerlessDataProcessingPipeline/Latencies --metric-name Latency --start-time $start_time --end-time $end_time --period 1 --statistics Average | jq '[.Datapoints[].Average]' > "$output_file"