Docs deploy via Terraform
[ci-management.git] / jjb / scripts / setup_executor_env.sh
1 #!/bin/bash
2
3 # Copyright (c) 2020 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 echo "---> jjb/scripts/setup_executor_env.sh"
17
18 set -e -o pipefail
19
20 OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
21 OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
22 OS_ARCH=$(uname -m)
23 dockerfile="/scratch/docker-build/Dockerfile"
24 file_delimiter="----- %< -----"
25 long_line="************************************************************************"
26 downloads_cache="/root/Downloads"
27
28 # Node info
29 echo "$long_line"
30 echo "Executor Runtime Attributes:"
31 echo "OS: $OS_ID-$OS_VERSION_ID"
32 echo "Arch: $OS_ARCH"
33 echo "Nomad Hostname: $(grep search /etc/resolv.conf | cut -d' ' -f2 | head -1)"
34 echo "Container ID: $(hostname)"
35
36 echo "$long_line"
37 if [ -f "$dockerfile" ] ; then
38     echo -e "Executor Dockerfile: ${dockerfile}\n${file_delimiter}"
39     cat $dockerfile
40     echo "$file_delimiter"
41 else
42     echo "Unknown Executor: '$dockerfile' not found!"
43 fi
44
45 # Performance analysis
46 perf_trials=2
47 perf_interval=1
48 if [ "$OS_ID" == "ubuntu" ] || [ "$OS_ID" = "debian" ] ; then
49     SYSSTAT_PATH="/var/log/sysstat"
50 elif [ "$OS_ID" == "centos" ] ; then
51     if [ "$OS_VERSION_ID" = "7" ] ; then
52         SYSSTAT_PATH="/var/log/sa/sa02"
53     else
54         SYSSTAT_PATH="/var/log/sa"
55     fi
56 fi
57 echo "$long_line"
58 echo "Virtual memory stat"
59 vmstat ${perf_interval} ${perf_trials}
60 echo "CPU time breakdowns per CPU"
61 mpstat -P ALL ${perf_interval}  ${perf_trials}
62 echo "Per-process summary"
63 pidstat ${perf_interval} ${perf_trials}
64 echo "Block device stats"
65 iostat -xz ${perf_interval} ${perf_trials}
66 echo "Memory utilization"
67 free -m
68 echo "Network interface throughput"
69 sar -n DEV -o ${SYSSTAT_PATH} ${perf_interval} ${perf_trials}
70 echo "TCP metrics"
71 sar -n TCP,ETCP -o ${SYSSTAT_PATH} ${perf_interval} ${perf_trials}
72
73 # SW stack
74 echo "$long_line"
75 echo "Executor package list:"
76 if [ "$OS_ID" == "ubuntu" ] || [ "$OS_ID" = "debian" ] ; then
77     dpkg-query -W -f='${binary:Package}\t${Version}\n' | column -t || true
78 elif [ "$OS_ID" == "centos" ] ; then
79     yum list installed || true
80 fi
81
82 echo "$long_line"
83 echo "Python3 package list:"
84 pip3 list 2>/dev/null | column -t || true
85
86 echo "$long_line"
87 echo "Executor Downloads cache '$downloads_cache':"
88 ls -lh "$downloads_cache" || true
89
90 echo "$long_line"
91 echo "DNS nameserver config in '/etc/resolv.conf':"
92 cat /etc/resolv.conf || true
93
94 echo "$long_line"
95 if [ -n "$(which ccache || true)" ] ; then
96     if  [ -z "${CCACHE_DIR:-}" ] || [ ! -d "$CCACHE_DIR" ] ; then
97         echo "CCACHE_DIR='$CCACHE_DIR' is missing, disabling CCACHE..."
98         export CCACHE_DISABLE="1"
99     fi
100     if [ -n "${CCACHE_DISABLE:-}" ] ; then
101         echo "CCACHE_DISABLE = '$CCACHE_DISABLE'"
102     fi
103     echo "ccache statistics:"
104     ccache -s
105 else
106     echo "WARNING: ccache is not installed!"
107     export CCACHE_DISABLE="1"
108 fi
109 echo "$long_line"