-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.sh
36 lines (29 loc) · 1018 Bytes
/
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
30
31
32
33
34
35
36
export JOB_UUID="$1"
rm -rf ${JOB_UUID}
mkdir ${JOB_UUID}
cd ${JOB_UUID}
echo "timestamp,num_instances,mem_min,mem_median,mem_max"
echo "timestamp,num_instances,mem_min,mem_median,mem_max" >> monitor_log
while true; do
# Timestamp.
export TIMESTAMP=$(date +%Y%m%d-%H%M%S)
# Poll instances.
gcloud compute instances list \
| grep ${JOB_UUID} \
| grep RUNNING \
| awk '{print $1 "," $2}' \
| parallel -k --jobs 64 --colsep ',' 'timeout 20 bash ../poll.sh {1} {2} 2>/dev/null' \
> data.$TIMESTAMP
# Check number of instances.
export NUM_INSTANCES=$(wc -l <data.$TIMESTAMP)
if [ ${NUM_INSTANCES} == 0 ]; then
exit
fi
# Extract just the memory statistics.
export F=memory.$TIMESTAMP
cut -d',' -f3 data.$TIMESTAMP | grep -v '^$' > $F
# Write report.
export REPORT="$TIMESTAMP,${NUM_INSTANCES},$(datamash min 1 <$F),$(datamash median 1 <$F),$(datamash max 1 <$F)"
echo $REPORT
echo $REPORT >> monitor_log
done