Upgrade pre-commit hook repos to latest
[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 OS=$(facter operatingsystem)
15 case "$OS" in
16     Ubuntu)
17         os_release=$(facter operatingsystemrelease)
18         case $os_release in
19             16.04|18.04)
20                 if ! systemctl status sysstat > /dev/null; then
21                     exit 0
22                 fi
23                 ;;
24             14.04)
25                 if [[ ! -f /etc/default/sysstat ]] ||
26                       ! grep --quiet 'ENABLED="true"' /etc/default/sysstat; then
27                     exit 0
28                 fi
29                 ;;
30             *)
31                 echo "ERROR: Unknown Release: Ubuntu $os_release"
32                 exit 1
33                 ;;
34         esac
35         SYSSTAT_PATH="/var/log/sysstat"
36     ;;
37     CentOS|RedHat)
38         SYSSTAT_PATH="/var/log/sa"
39     ;;
40     *)
41         # nothing to do
42         exit 0
43     ;;
44 esac
45
46 SAR_DIR="$WORKSPACE/archives/sar-reports"
47 mkdir -p "$SAR_DIR"
48 cp "$SYSSTAT_PATH/"* "$_"
49 # convert sar data to ascii format
50 while IFS="" read -r sarfilenum
51 do
52     [ -f "$sarfilenum" ] && LC_TIME=POSIX sar -A -f "$sarfilenum" > "$SAR_DIR/sar${sarfilenum//[!0-9]/}"
53 done < <(find "$SYSSTAT_PATH" -name "sa[0-9]*" || true)
54
55 # DON'T fail build if script fails.
56 exit 0