按小时统计unix机器内存和cpu使用率

给脚本赋权限
chmod 755 *.sh

后台执行该脚本
nohup sum_capa.sh &

x=0
totMem=`vmstat | grep 'mem=' | awk -F\= '{ print $3 }' | awk -F\M '{print $1 }'`
totMem1=` echo "$totMem * 200 " | bc `
while true
do
strDate=`date +"%Y%m%d"`
strTime=`date +"%Y%m%d%H"`
strRun=`vmstat 1 4 | tail -1 | awk '{ print " "$3" "$14" "$15 }' `
echo $strTime" "$totMem1$strRun >> capa_$strDate.txt

sleep 56

x=`expr $x + 1`
if [ $x -gt 3000 ]
then
break
fi

done


三天后得到统计数据,执行该脚本 get_capa.sh

if [ "$#" -ne 1 ]
then
echo "Usage:get_capa.sh yyyymmdd"
exit 1
fi

echo "Hour Mem(%) Cpu(%) " > capa_hour_$1.txt
hh="00"
x=0
while true
do
if [ x -lt 10 ]
then
hh="0"$x
else
hh=$x
fi

strTmp=`grep $1$hh capa_$1.txt | awk 'BEGIN{allMem=0;useMem=0;memRate=0;cpuRate=0;num=0;allCpu=0;} { allMem=allMem+$2;useMem=useMem+$3;num=num+1;allCpu=allCpu+$4+$5;} END{ if (allMem>0) { memRate=useMem*100/allMem;cpuRate=allCpu/num;} print memRate" "cpuRate}'`

echo $hh" "$strTmp >> capa_hour_$1.txt

x=`expr $x + 1`
if [ $x -gt 23 ]
then
break
fi

done

cat capa_hour_$1.txt



统计交易量 sum_tran.sh

if [ "$#" -ne 3 ]
then
echo "Usage:sum_tran.sh yyyy mm dd"
exit 1
fi

echo "Hour Trans" > tran_hour_$1$2$3.txt
hh="00"
x=0
while true
do
if [ x -lt 10 ]
then
hh="0"$x
else
hh=$x
fi

num=`grep TxRunAction /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|grep $1":"$hh |wc -l`

echo $hh" "$num >> tran_hour_$1$2$3.txt


x=`expr $x + 1`
if [ $x -gt 23 ]
then
break
fi

done

cat tran_hour_$1$2$3.txt

num=`cat /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log | wc -l`
echo "TotTrans="$num

num=`grep TxRunAction /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|wc -l`
echo "TxRunTrans="$num

num=`grep LinkageTX /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|wc -l`
echo "LinkTrans="$num



统计20w数据表 db_20w.sh

if [ "$#" -ne 1 ]
then
echo "Usage:db_20w.sh ddmmyyyy"
exit 1
fi

db2 "connect to ecap "
db2 "select count(*) from ecapdb.t_tran_log where HEAD_DATE='"$1"' "

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值