#! /bin/bash
if [ "$#" -lt 2 ] # $# 传递给脚本或函数的参数个数
then
echo "Usage: $0 program" # $0 脚本名称
exit -1;
fi
SLEEP_TIME=$1
LOG=$2
while true
do
#线程数
thread_num=`sar -q 1 1 | awk '/^Average:/{print $3}'`
#句柄数
open_files=`sar -v 1 1 | awk '/^Average:/{print $3}'`
#cpu占用率
cpu_info=`sar -u 1 1 | awk '/^Average:/{print 100-$8}'`
#内存使用量
mem=`sar -r 1 1 | awk '/^Average:/{print ($3-$5-$6)/($2+$3)*100}'`
#IO传输总量
io=`sar -b 1 1 | awk '/^Average:/{print $2}'`
#输出到日志文件
echo -e "`date +"%Y-%m-%d %H:%M:%S"`,${cpu_info},${mem},${io},${thread_num},${open_files}" >> ${LOG}
sleep $SLEEP_TIME
done