公司经常做压力测试,因此我写了一个脚本。记录系统的性能信息,以便以后进行分析。很不错的脚本哦!希望给想监控系统状态的朋友们节省一些时间。
#!/bin/bash
################################################
#Function:collect and record system performance#
# #
#write by: wade #
#version:1.0 date:20080128 #
#For Linux #
################################################
#
#define the variable
#
OS=`uname -s`
HOST=`hostname`
DATE=`date +'%m%d'`
TIME=`date +'%Y%m%d%H%M'`
DIR=/home/tools/sys_perf
perf_file=$DIR/log/$DATE/"$HOST"_sys_perf_$DATE
if [ ! -d $DIR ]
then mkdir $DIR
fi
cd $DIR
if [ ! -d $DIR/log ]
then mkdir $DIR/log
fi
if [ ! -d log/$DATE ]
then mkdir log/$DATE
fi
#save load data to temporary file
uptime | awk '{print substr($(NF-2),1,4)}'>temp
#save cpu/mem/swap data to temporary file
sar -u -r 3 3 |grep Average >> temp
load=`sed -n 1p temp`
cpu_use=`sed -n 3p temp|awk '{print (100-$NF)"%"}'`
io_wait=`sed -n 3p temp|awk '{print $6"%"}'`
mem_use=`sed -n 5p temp|awk '{print $4"%"}'`
swap_use=`sed -n 5p temp|awk '{print $(NF-1)"%"}'`
if [ ! -f $perf_file ]
then echo "TIME load cpu_use io_wait mem_use swap_use"> $perf_file
echo "===============================================================================">>$perf_file
fi
#delete the temporary file
echo -n $TIME >>$perf_file
echo -n " "$load >>$perf_file
echo -n " "$cpu_use >> $perf_file
echo -n " "$io_wait >>$perf_file
echo -n " "$mem_use >> $perf_file
echo " "$swap_use >> $perf_file
rm -f temp
来源:http://blog.sina.com.cn/s/blog_4d8a2c970100f6ui.html
#!/bin/bash
################################################
#Function:collect and record system performance#
# #
#write by: wade #
#version:1.0 date:20080128 #
#For Linux #
################################################
#
#define the variable
#
OS=`uname -s`
HOST=`hostname`
DATE=`date +'%m%d'`
TIME=`date +'%Y%m%d%H%M'`
DIR=/home/tools/sys_perf
perf_file=$DIR/log/$DATE/"$HOST"_sys_perf_$DATE
if [ ! -d $DIR ]
then mkdir $DIR
fi
cd $DIR
if [ ! -d $DIR/log ]
then mkdir $DIR/log
fi
if [ ! -d log/$DATE ]
then mkdir log/$DATE
fi
#save load data to temporary file
uptime | awk '{print substr($(NF-2),1,4)}'>temp
#save cpu/mem/swap data to temporary file
sar -u -r 3 3 |grep Average >> temp
load=`sed -n 1p temp`
cpu_use=`sed -n 3p temp|awk '{print (100-$NF)"%"}'`
io_wait=`sed -n 3p temp|awk '{print $6"%"}'`
mem_use=`sed -n 5p temp|awk '{print $4"%"}'`
swap_use=`sed -n 5p temp|awk '{print $(NF-1)"%"}'`
if [ ! -f $perf_file ]
then echo "TIME load cpu_use io_wait mem_use swap_use"> $perf_file
echo "===============================================================================">>$perf_file
fi
#delete the temporary file
echo -n $TIME >>$perf_file
echo -n " "$load >>$perf_file
echo -n " "$cpu_use >> $perf_file
echo -n " "$io_wait >>$perf_file
echo -n " "$mem_use >> $perf_file
echo " "$swap_use >> $perf_file
rm -f temp
来源:http://blog.sina.com.cn/s/blog_4d8a2c970100f6ui.html
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2822/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表