From 842333dd193f86a0a8490363a0f918e3e9220a6a Mon Sep 17 00:00:00 2001 From: x p k Date: Wed, 22 Apr 2020 17:36:36 +0800 Subject: [PATCH] UPD: renamed file --- sh/sar-analysis.sh | 17 +++++++++++++++++ sh/sar-weekly.sh | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100755 sh/sar-analysis.sh delete mode 100755 sh/sar-weekly.sh diff --git a/sh/sar-analysis.sh b/sh/sar-analysis.sh new file mode 100755 index 0000000..611ed7c --- /dev/null +++ b/sh/sar-analysis.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +SARDIR=/var/log/sysstat +if [ -d /var/log/sa ]; then + SARDIR=/var/log/sa +fi +# echo "CPUUsed MEMUsed SWAPUsed IOWait" +for f in $(ls $SARDIR/sa[0123]*); do +# SARDate=$(stat $f | grep Modify | awk '{print $2}') +CPUUsed=$(sar -f $f | tail -1 | awk '{print 100-$NF}') +MEMUsed=$(sar -r -f $f | tail -1 | grep -Eo '[0-9]+\.[0-9]+' | head -1) +SWAPUsed=$(sar -S -f $f | tail -1 | awk '{print $4}') +IOWait=$(sar -f $f | tail -1 | awk '{print $6}') +echo "$CPUUsed $MEMUsed $SWAPUsed $IOWait" >> /tmp/sar-report.txt +done +cat /tmp/sar-report.txt | awk '{for (i=1;i<=NF;i++){a[i]+=$i;}} END {for (i=1;i<=NF;i++){printf "%.2f", a[i]/NR; printf "\t"};printf "\n"}' | awk '{ if ($1 > 50) print "high cpu",$1}; {if ($3 > 20) print "high swap", $3}; {if ($4 > 10) print "high iowait", $4}' + +# rm -f /tmp/sar-report.txt diff --git a/sh/sar-weekly.sh b/sh/sar-weekly.sh deleted file mode 100755 index 1acf928..0000000 --- a/sh/sar-weekly.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -SARDIR=/var/log/sysstat -if [ -d /var/log/sa ]; then - SARDIR=/var/log/sa -fi -echo "Date CPUUsed MEMUsed SWAPUsed IOWait" > /tmp/sar-report.txt -for f in $(ls $SARDIR/sa[0123]*); do -SARDate=$(stat $f | grep Modify | awk '{print $2}') -CPUUsed=$(sar -f $f | tail -1 | awk '{print 100-$NF}') -MEMUsed=$(sar -r -f $f | tail -1 | grep -Eo '[0-9]+\.[0-9]+' | head -1) -SWAPUsed=$(sar -S -f $f | tail -1 | awk '{print $4}') -IOWait=$(sar -f $f | tail -1 | awk '{print $6}') -echo "$SARDate $CPUUsed $MEMUsed $SWAPUsed $IOWait" >> /tmp/sar-report.txt -done -cat /tmp/sar-report.txt | column -t -rm -f /tmp/sar-report.txt