2cedd9adc6d24d71.jpg

CPU 平均值

#!/bin/sh
echo "+----------------------------------------------------------------------------------+"
echo "|Average:         CPU     %user     %nice   %system   %iowait    %steal     %idle  |"
echo "+----------------------------------------------------------------------------------+"
for file in `ls -tr /var/log/sa/sa* | grep -v sar`
do
    dat=`sar -f file | head -n 1 | awk '{print4}'`
    echo -n dat
    sar -ffile  | grep -i Average | sed "s/Average://"
done
echo "+----------------------------------------------------------------------------------+"

平均内存利用率

#!/bin/sh
echo "+-------------------------------------------------------------------------------------------------------------------+"
echo "|Average:       kbmemfree kbmemused  %memused kbbuffers kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty  |"
echo "+-------------------------------------------------------------------------------------------------------------------+"
for file in `ls -tr /var/log/sa/sa* | grep -v sar`
do
    dat=`sar -f file | head -n 1 | awk '{print4}'`
    echo -n dat
    sar -r -ffile  | grep -i Average | sed "s/Average://"
done
echo "+-------------------------------------------------------------------------------------------------------------------+"

CPU 和内存平均利用率

#!/bin/bash
for file in `ls -tr /var/log/sa/sa* | grep -v sar`
do
    sar -f file | head -n 1 | awk '{print4}'
    echo "-----------"
    sar -u -f file | awk '/Average:/{printf("CPU Average: %.2f%\n"), 100 -8}'
    sar -r -f file | awk '/Average:/{printf("Memory Average: %.2f%\n"),((3-5-6)/(2+3)) * 100 }'
    printf "\n"
done

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code