UPD: renamed file
This commit is contained in:
parent
477f7b202c
commit
842333dd19
17
sh/sar-analysis.sh
Executable file
17
sh/sar-analysis.sh
Executable file
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user