AIX下内存泄漏的监控

内存泄露主要就是监控进程的内存消耗,AIX下可以通过ps vg得到内存的消耗量,从而比较
另外,有个很有用的脚本:post_vg.sh 用来比较内存的增加

 


下面是一个以前监控内存泄漏问题时的一个自动脚本

 

------------------
-- run_ps_vg.sh --
------------------
#crontab -e
#10,20,30,40,50,59 9-20 * * * /home/root/run_vg.sh /home/root/postvg.trc

fn=$1

sysdate=`date`
fname="zzz ***"$sysdate
echo $fname >> $fn
ps vg >> $fn

 


------------------------
-- analyze_post_vg.sh --
------------------------
fn=$1

cat $fn |grep -n zzz|sed 's/ /_/g'|sed 's/***//g'|sed 's/zzz_//g'|sed 's/:/ /' > tmp.out
       
while read hh rq
do
  hh_list=$hh_list" "$hh
  rq_list=$rq_list" "$rq
done<tmp.out

hh_array=($hh_list)
rq_array=($rq_list)

for((i=0;i<${#hh_array[@]};i++))
do          
  let cou=${#hh_array[@]}-1        
  if [ $i -eq $cou ]; then
    let hh=${hh_array[i]}+1 
    tail -n +$hh $fn > vg_${rq_array[i]}.trc
  else
    let thh=${hh_array[i]}+1
    let hhh=${hh_array[i+1]}-1
    head -n $hhh $fn |tail -n +$thh > vg_${rq_array[i]}.trc
  fi      
done

ls -l |grep vg.*trc |awk '{print $9}' > tmp.out

while read trcfile
do
  trcfile_list=$trcfile_list" "$trcfile
done<tmp.out

#echo $trcfile_list
trcfile_array=($trcfile_list)

for((i=0;i<${#trcfile_array[@]};i++))
do          
  let cou=${#trcfile_array[@]}-1        
  if [ $i -eq $cou ]; then
 echo "end"
  else
    endfile=${trcfile_array[i+1]}
    begfile=${trcfile_array[i]}
 echo $begfile" "$endfile
    ./postvg.sh $begfile $endfile|awk '$5 != 0 {print $0}'
  fi      
done

 


使用:


1.在AIX系统上挂了定时任务,定时执行run_ps_vg.sh,参数入输出的文件名


2.使用analyze_post_vg.sh分析输出,该脚本主要是用来调用post_vg.sh脚本。

 

参数为上一步的输出文件,输出如下


 postvg.trc vg_Fri_Mar_13_10:40:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
             zzz                           0              0               0
 *** Total Delta 0
 vg_Fri_Mar_13_10:40:00_BEIST_2009.trc vg_Fri_Mar_13_10:50:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
          991642    oracleJ             5404           5736             332
          721192    oracleJ             4932           5988            1056
          664050    /oracle             6984           6988               4
          381226    oracleJ             4392           4404              12
         1163288    oracleJ             4396           4556             160
          512110    oracleJ             4264           4308              44
          307418    oracleJ             4392           4500             108
 *** Total Delta 1716


 vg_Fri_Mar_13_10:50:00_BEIST_2009.trc vg_Fri_Mar_13_10:59:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
          987550    /home/r             3284           3296              12
 *** Total Delta 12


 vg_Fri_Mar_13_10:59:00_BEIST_2009.trc vg_Fri_Mar_13_11:10:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
          987550    /home/r             3296           3304               8
 *** Total Delta 8


 vg_Fri_Mar_13_11:10:00_BEIST_2009.trc vg_Fri_Mar_13_11:20:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
         1745300    oracleJ             4360           4376              16
          987550    /home/r             3304           3308               4
         1167472    oracleJ             4320           4636             316
 *** Total Delta 336


 vg_Fri_Mar_13_11:20:00_BEIST_2009.trc vg_Fri_Mar_13_11:30:00_BEIST_2009.trc
             pid       Name      Before Size     After Size           Delta
          602482    oracleJ             4892           4464            -428
          987550    /home/r             3308           3316               8
         1167472    oracleJ             4636           4320            -316


3.通过对结果进行检查,可以查看一个进程使用的内存是否在持续增大


 bash-3.00# cat result.txt|grep 987550
      987550    /home/r             3284           3296              12
      987550    /home/r             3296           3304               8
      987550    /home/r             3304           3308               4
      987550    /home/r             3308           3316               8
      987550    /home/r             3316           3320               4
      987550    /home/r             3320           3324               4
      987550    /home/r             3324           3328               4
      987550    /home/r             3328           3332               4
      987550    /home/r             3332           3348              16
      987550    /home/r             3348           3356               8
      987550    /home/r             3356           3360               4
      987550    /home/r             3360           4604            1244
      987550    /home/r             4604           6468            1864
      987550    /home/r             6468           6472               4
      987550    /home/r             6472           6484              12
      987550    /home/r             6484           6988             504
      987550    /home/r             6988           7020              32
      987550    /home/r             7020           7056              36
      987550    /home/r             7056           7064               8
      987550    /home/r             7064           7096              32
      987550    /home/r             7096           7120              24
      987550    /home/r             7120           7160              4

 

 

 

转自: http://space.itpub.net/8242091/viewspace-586994

 


你可能感兴趣的:(Date,list,脚本,AIX,360,任务)