|
5#
楼主 |
发表于 2012-2-23 17:57:22
|
只看该作者
#!/bin/sh
# 设置测试结果源文件的路径
REPORT_HOME=/home
SAR_FILE=$REPORT_HOME/result
if [ -f "$SAR_FILE" ]
then
echo "Collecting the test data..."
{
#collect cpu-usage info
sar -u -f $SAR_FILE | awk '/all/{print 100-$8}' > $REPORT_HOME/cpu-usage.xls
if [ $? -ne 0 ]
then
echo "Failed in collecting CPU info!"
else
echo "Succeed in collecting CPU info: ${?}"
fi
} &
{
#collect ram-usage
sar -r -f $SAR_FILE | awk '!/kbmemfree/&&/^([0-9]|Average)/{print ($3-$5-$6)*100/($2+$3)}' > $REPORT_HOME/ram-usage.xls
if [ $? -ne 0 ]
then
echo "Failed in collecting RAM info!"
else
echo "Succeed in collecting RAM info: ${?}"
fi
} &
#collect disk info
{
awk 'BEGIN{OFS="\t";print "rd_MB/s","wr_MB/s","avgqu-sz","%util"}' > $REPORT_HOME/disk-info.xls
sar -d -f $SAR_FILE | awk '$2=="dev8-16"||$2=="dev8-32"||$2=="dev8-48"||$2=="dev8-64"||$2=="dev8-80"||$2=="dev8-96"||$2=="dev8-112"||$2=="dev8-128"||$2=="dev8-144"' | awk 'BEGIN{OFS="\t"}{sum_rd+=$4;sum_wr+=$5;sum_avgqu+=$7;sum_util+=$10;if(NR%9==0){print sum_rd/(9*2*1024),sum_wr/(9*2*1024),sum_avgqu/9,sum_util/9;sum_rd=0;sum_wr=0;sum_avgqu=0;sum_util=0}}' >> $REPORT_HOME/disk-info.xls
if [ $? -ne 0 ]
then
echo "Failed in collecting DISK info!"
else
echo "Succeed in collecting DISK info: ${?}"
fi
} &
#collect net-usage
{
awk 'BEGIN{OFS="\t";print "rx_MB/s","tx_MB/s","%net"}' > $REPORT_HOME/net-usage.xls
sar -n DEV -f $SAR_FILE | awk 'BEGIN{OFS="\t"}$2=="eth0"{print $5/1024,$6/1024,($5+$6)/(1024*1.25)}' >> $REPORT_HOME/net-usage.xls
if [ $? -ne 0 ]
then
echo "Failed in collecting NET info!"
else
echo "Succeed in collecting NET info: ${?}"
fi
} &
echo "Collecting data is done."
else
echo "The monitor data file is not exist!"
fi |
|