OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
2 # | |
3 # Logs into the specified Skia compute engine instance, parses out the | |
4 # persistent disk usage and compares it against the threshold. | |
5 # | |
6 # The SKIA_COMPUTE_ENGINE_HOSTNAME environment variable is the hostname of the | |
7 # compute engine instance we want to check. The PERSISTENT_DISK_NAME is the | |
8 # mounted path of the disk we want to check. | |
9 # | |
10 # Sample Usage: | |
11 # SKIA_COMPUTE_ENGINE_HOSTNAME=skia-master-a.c.skia-buildbots.google.com.intern
al \ | |
12 # PERSISTENT_DISK_NAME=/home/default/skia-master \ | |
13 # DELETE_TRYBOT_DIRS=True \ | |
14 # bash check_compute_engine_disk_usage.sh | |
15 # | |
16 # Can also optionally specify the environment variable THRESHOLD (default 90). | |
17 # | |
18 | |
19 THRESHOLD=${THRESHOLD:-90} | |
20 | |
21 # Check to see if the script can log into the compute engine instance. | |
22 ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o \ | |
23 StrictHostKeyChecking=no -p 22 $SKIA_COMPUTE_ENGINE_HOSTNAME 'df -h' | |
24 ret_code=`echo $?` | |
25 if [ "$ret_code" -ne 0 ]; then | |
26 echo -e "There was an error logging into the compute engine instance! Return c
ode: $ret_code" | |
27 exit $ret_code | |
28 fi | |
29 | |
30 function check_disk_space_usage { | |
31 complete_output=`ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o \ | |
32 StrictHostKeyChecking=no -p 22 $SKIA_COMPUTE_ENGINE_HOSTNAME 'df -h' | \ | |
33 grep $PERSISTENT_DISK_NAME`; IFS=' ' v=($complete_output); \ | |
34 percent_used=${v[4]/\%/} | |
35 echo $percent_used | |
36 } | |
37 | |
38 # Log into the compute engine instance and parse the percentage used of the | |
39 # persistent disk. | |
40 percent_used=`check_disk_space_usage` | |
41 if [ "$percent_used" -lt "$THRESHOLD" ]; then | |
42 echo -e "\nThe percentage used ($percent_used%) is below the threshold ($THRES
HOLD%).\n" | |
43 exit 0 | |
44 else | |
45 echo -e "\nThe percentage used ($percent_used%) is at or beyond the threshold
($THRESHOLD%).\n" | |
46 if [[ ! -z "$DELETE_TRYBOT_DIRS" ]]; then | |
47 DELETE_CMD="rm -rf ~/skia-slave/buildbot/skiabot-linux-compile-vm-*/buildbot
/third_party/chromium_buildbot/slave/*-Trybot; rm -rf | |
48 ~/skia-slave/buildbot/skiabot-linux-compile-vm-*/buildbot/third_party/chromium_b
uildbot/slave/*.log.*" | |
49 ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o \ | |
50 StrictHostKeyChecking=no -p 22 default@$SKIA_COMPUTE_ENGINE_HOSTNAME "$DEL
ETE_CMD" | |
51 echo "Deleted the Trybot builder directories." | |
52 percent_used=`check_disk_space_usage` | |
53 echo "The percentage used is now: $percent_used%" | |
54 else | |
55 echo -e "Please make room on the compute engine instance by deleting unneede
d files.\n" | |
56 exit 1 | |
57 fi | |
58 fi | |
59 | |
OLD | NEW |