首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

按钟头统计unix机器内存和cpu使用率

2012-07-05 
按小时统计unix机器内存和cpu使用率给脚本赋权限chmod 755 *.sh后台执行该脚本nohup sum_capa.sh &x0

按小时统计unix机器内存和cpu使用率
    给脚本赋权限
chmod 755 *.sh

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

x=0totmem=`vmstat | grep 'mem=' | awk -f\= '{ print $3 }' | awk -f\m '{print $1 }'`totmem1=` echo "$totmem * 200 " | bc `while truedo    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    fidone


三天后得到统计数据,执行该脚本 get_capa.sh
if [ "$#" -ne 1 ]then    echo "usage:get_capa.sh yyyymmdd"    exit 1fiecho "hour         mem(%)        cpu(%) " > capa_hour_$1.txthh="00"x=0while truedo    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    fidonecat capa_hour_$1.txt


统计交易量 sum_tran.sh
if [ "$#" -ne 3 ]then    echo "usage:sum_tran.sh yyyy mm dd"    exit 1fiecho "hour         trans" > tran_hour_$1$2$3.txthh="00"x=0while truedo    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    fidonecat tran_hour_$1$2$3.txtnum=`cat /usr/ibm/httpserver/logs/access.$1.$2.$3.log | wc -l`echo "tottrans="$numnum=`grep txrunaction /usr/ibm/httpserver/logs/access.$1.$2.$3.log|wc -l`echo "txruntrans="$numnum=`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 1fidb2 "connect to ecap "db2 "select count(*) from ecapdb.t_tran_log where head_date='"$1"' "
  1 楼 codingstandards 2011-10-15   楼主,整理一下格式啊

热点排行