Merge "Restore vpp-csit-*tx2 jobs in production"
[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 # Requires all nomad client machines to run the following command
29 # and mount /scratch/nomad into the docker container:
30 # sudo mkdir -p /scratch/nomad && echo "$(hostname)-$(uname -m)" | sudo tee /scratch/nomad/nomad-client
31 nomad_client_file="/scratch/nomad/nomad-client"
32 if [ -f "$nomad_client_file" ] ; then
33     NOMAD_CLIENT="$(cat $nomad_client_file)"
34 else
35     NOMAD_CLIENT="Unknown"
36 fi
37
38 # Node info
39 echo "$long_line"
40 echo "Executor Runtime Attributes:"
41 echo "OS: $OS_ID-$OS_VERSION_ID"
42 echo "Arch: $OS_ARCH"
43 echo "Nomad Client Hostname: $NOMAD_CLIENT"
44 echo "Container ID: $(hostname)"
45
46 echo "$long_line"
47 if [ -f "$dockerfile" ] ; then
48     echo -e "Executor Dockerfile: ${dockerfile}\n${file_delimiter}"
49     cat $dockerfile
50     echo "$file_delimiter"
51 else
52     echo "Unknown Executor: '$dockerfile' not found!"
53 fi
54
55 # Performance analysis
56 perf_trials=2
57 perf_interval=1
58 if [ "$OS_ID" == "ubuntu" ] || [ "$OS_ID" = "debian" ] ; then
59     SYSSTAT_PATH="/var/log/sysstat"
60 elif [ "$OS_ID" == "centos" ] ; then
61     if [ "$OS_VERSION_ID" = "7" ] ; then
62         SYSSTAT_PATH="/var/log/sa/sa02"
63     else
64         SYSSTAT_PATH="/var/log/sa"
65     fi
66 fi
67 echo "$long_line"
68 echo "Virtual memory stat"
69 vmstat ${perf_interval} ${perf_trials}
70 echo "CPU time breakdowns per CPU"
71 mpstat -P ALL ${perf_interval}  ${perf_trials}
72 echo "Per-process summary"
73 pidstat ${perf_interval} ${perf_trials}
74 echo "Block device stats"
75 iostat -xz ${perf_interval} ${perf_trials}
76 echo "Memory utilization"
77 free -m
78 echo "Network interface throughput"
79 sar -n DEV -o ${SYSSTAT_PATH} ${perf_interval} ${perf_trials}
80 echo "TCP metrics"
81 sar -n TCP,ETCP -o ${SYSSTAT_PATH} ${perf_interval} ${perf_trials}
82
83 # SW stack
84 echo "$long_line"
85 echo "Executor package list:"
86 if [ "$OS_ID" == "ubuntu" ] || [ "$OS_ID" = "debian" ] ; then
87     dpkg-query -W -f='${binary:Package}\t${Version}\n' | column -t || true
88 elif [ "$OS_ID" == "centos" ] ; then
89     yum list installed || true
90 fi
91
92 echo "$long_line"
93 echo "Python3 package list:"
94 pip3 list 2>/dev/null | column -t || true
95
96 echo "$long_line"
97 echo "Executor Downloads cache '$downloads_cache':"
98 ls -lh "$downloads_cache" || true
99
100 echo "$long_line"
101 echo "DNS nameserver config in '/etc/resolv.conf':"
102 cat /etc/resolv.conf || true
103
104 echo "$long_line"
105 if [ -n "$(which ccache || true)" ] ; then
106     if  [ -z "${CCACHE_DIR:-}" ] || [ ! -d "$CCACHE_DIR" ] ; then
107         echo "CCACHE_DIR='$CCACHE_DIR' is missing, disabling CCACHE..."
108         export CCACHE_DISABLE="1"
109     fi
110     if [ -n "${CCACHE_DISABLE:-}" ] ; then
111         echo "CCACHE_DISABLE = '$CCACHE_DISABLE'"
112     fi
113     echo "ccache statistics:"
114     ccache -s
115 else
116     echo "WARNING: ccache is not installed!"
117     export CCACHE_DISABLE="1"
118 fi
119 echo "$long_line"