UPD: added swap

This commit is contained in:
xpk 2020-04-22 16:14:50 +08:00
parent 6da77dc13b
commit 477f7b202c
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86

View File

@ -3,13 +3,14 @@ SARDIR=/var/log/sysstat
if [ -d /var/log/sa ]; then if [ -d /var/log/sa ]; then
SARDIR=/var/log/sa SARDIR=/var/log/sa
fi fi
echo "Date CPUUsed MEMUsed IOWait" > /tmp/sar-report.txt echo "Date CPUUsed MEMUsed SWAPUsed IOWait" > /tmp/sar-report.txt
for f in $(ls $SARDIR/sa[0123]*); do for f in $(ls $SARDIR/sa[0123]*); do
SARDate=$(stat $f | grep Modify | awk '{print $2}') SARDate=$(stat $f | grep Modify | awk '{print $2}')
CPUUsed=$(sar -f $f | tail -1 | awk '{print 100-$NF}') 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) 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}') IOWait=$(sar -f $f | tail -1 | awk '{print $6}')
echo "$SARDate $CPUUsed $MEMUsed $IOWait" >> /tmp/sar-report.txt echo "$SARDate $CPUUsed $MEMUsed $SWAPUsed $IOWait" >> /tmp/sar-report.txt
done done
cat /tmp/sar-report.txt | column -t cat /tmp/sar-report.txt | column -t
rm -f /tmp/sar-report.txt rm -f /tmp/sar-report.txt