不得不服中国移动客户的严谨。在配置Weblogic集群中我们系统与N个第三方系统交互的线程队列的大小时,他们要我们跟据现网日志分析各系统的请求压力,而且要拿出各种统计数据,然后根据这样统计数据来决点各线程池的大小。俺们系统日志,N多种,一天产生的量基本都是几十万级的,加起来过千万。所以,写这个Shell方便分析,觉得这个Shell还算通用,所以发布上来,希户能给后来者也带来方便。
pdates = $ 2 ;
pkeywds = $ 3 ;
keywd = "" ;
method_count()
{
echo " Begin method method_count! " $keywd ;
hs = " 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 " ;
for dt in $pdates ;
do
for h in $hs ;
do
tt = $dt " . " $h ;
kk = $tt " {1,}.* " $keywd ;
echo $dt " 日 " $h " 时的请求数: " ;
# echo $kk;
# cat $pfile|grep $dt"."$h|grep $keywd|wc -l;
grep $kk $pfile | wc - l;
done ;
done ;
echo " End method method_count! " ;
}
for k in $pkeywds ;
do
# if [ -n "$keywd" ];
# then
# echo JJJJJ $keywd;
# keywd=$keywd"|";
# fi
keywd = $keywd$k " {1,}.* " ;
done ;
method_count;
注意:上面Shell中的“}”与“{”请分别改为“/}”、“/{”。我代码中的"/"转义符,让CSDN系统去掉了。毫无疑问,这是CSDN的一个BUG。
执行结果:
Begin method method_count!Login/{1,/}.*ServiceID/{1,/}.*
2008-03-06ÈÕ00ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ01ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ02ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ03ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ04ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ05ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ06ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ07ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ08ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ09ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ10ʱµÄÇëÇóÊý£º
1
2008-03-06ÈÕ11ʱµÄÇëÇóÊý£º
2
2008-03-06ÈÕ12ʱµÄÇëÇóÊý£º
1
2008-03-06ÈÕ13ʱµÄÇëÇóÊý£º
1
2008-03-06ÈÕ14ʱµÄÇëÇóÊý£º
1
2008-03-06ÈÕ15ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ16ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ17ʱµÄÇëÇóÊý£º
280
2008-03-06ÈÕ18ʱµÄÇëÇóÊý£º
1
2008-03-06ÈÕ19ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ20ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ21ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ22ʱµÄÇëÇóÊý£º
0
2008-03-06ÈÕ23ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ00ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ01ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ02ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ03ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ04ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ05ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ06ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ07ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ08ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ09ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ10ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ11ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ12ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ13ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ14ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ15ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ16ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ17ʱµÄÇëÇóÊý£º
3
2008-03-08ÈÕ18ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ19ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ20ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ21ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ22ʱµÄÇëÇóÊý£º
0
2008-03-08ÈÕ23ʱµÄÇëÇóÊý£º
0
End method method_count!
后一次完善:
pdates = $ 2 ;
pkeywds = $ 3 ;
ppath = $ 4 ;
keywd = "" ;
tempf = " _temp_all.log " ;
method_count()
{
hs = " 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 " ;
for dt in $pdates ;
do
for h in $hs ;
do
tt = $dt " . " $h ;
kk = $tt " {1,}.* " $keywd ;
echo $pfile $dt " 日 " $h " 时的请求数: " ;
grep $kk $tempf | wc - l;
done ;
done ;
}
method_createtempfile()
{
mf = "" ;
for ff in $ppath /* ;
do
if [ -f $ff ];
then
case $ff in *$pfile*)
mf=$mf" "$ff;
esac
fi
done;
cat $mf > $tempf;
}
for k in $pkeywds;
do
keywd=$keywd$k"{1,}.*";
done;
if [ -z $ppath ];
then
ppath=".";
fi
echo begin analyse! keyword is $keywd
method_createtempfile;
method_count;
rm $tempf;
echo end analyse!