Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / sysstat.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> sysstat.sh"
12 set +e  # DON'T fail build if script fails.
13
14 if awk -F/ '$2 == "docker"' /proc/self/cgroup | read -r; then
15     exit 0
16 fi
17
18
19 OS=$(facter operatingsystem)
20 case "$OS" in
21     Ubuntu)
22         os_release=$(facter operatingsystemrelease)
23         case $os_release in
24             16.04|18.04|20.04)
25                 if ! systemctl status sysstat > /dev/null; then
26                     exit 0
27                 fi
28                 ;;
29             14.04)
30                 if [[ ! -f /etc/default/sysstat ]] || \
31                         ! grep --quiet 'ENABLED="true"' /etc/default/sysstat; then
32                     exit 0
33                 fi
34                 ;;
35             *)
36                 echo "ERROR: Unknown Release: Ubuntu $os_release"
37                 exit 1
38                 ;;
39         esac
40         SYSSTAT_PATH="/var/log/sysstat"
41     ;;
42     CentOS|RedHat)
43         SYSSTAT_PATH="/var/log/sa"
44     ;;
45     *)
46         # nothing to do
47         exit 0
48     ;;
49 esac
50
51 SAR_DIR="$WORKSPACE/archives/sar-reports"
52 mkdir -p "$SAR_DIR"
53 cp "$SYSSTAT_PATH/"* "$_"
54 # convert sar data to ascii format
55 while IFS="" read -r sarfilenum; do
56     [ -f "$sarfilenum" ] && LC_TIME=POSIX sar -A -f "$sarfilenum" > "$SAR_DIR/sar${sarfilenum//[!0-9]/}"
57 done < <(find "$SYSSTAT_PATH" -name "sa[0-9]*" || true)
58
59 # DON'T fail build if script fails.
60 exit 0