【转载】一个记录系统性能的脚本

原文: http://c20031776.blog.163.com/blog/static/6847162520097281120261/


公司经常做压力测试,因此我写了一个脚本。记录系统的性能信息,以便以后进行分析。很不错的脚本哦!希望给想监控系统状态的朋友们节省一些时间。



#!/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值