1,restime统计响应时间
#!/bin/bash #统计日志响应时间用 if [ $# -lt 1 ]; then echo "at least have one param; " echo "ex: restime a.log b.log *.log" exit 1 fi . lgq_config.sh for((i=1;i<=$#;i++));do opt=`echo ${!i} | grep "^\-F" | awk -F"F" ‘{print $2}‘` if [ x$opt = x"" ]; then file_list="$file_list ${!i}" else ff=$opt fi done echo $file_list | xargs cat | grep $ff | awk -F"$ff" ‘BEGIN{ max=0; min=10000; n=0; total=0; min_log=""; max_log=""; }{ t=$2+0; n++; total+=t; if(t>max) { max=t; max_log=$0; } if(t<min) { min=t; min_log=$0; } }END{ print "\033[32mavg time:\033[37m",total/n"ms"; print "\033[32mmax time:\033[37m",max"ms." print "\033[32mmin time:\033[37m",min"ms." print "\033[31mmax time log:\033[37m",max_log; print "\033[31mmin time log:\033[37m",min_log; }‘
2,qps 统计平均处理时长
#!/bin/bash #每秒平均处理请求次数 if [ $# -lt 1 ]; then echo "at least have one param; " echo "ex: qps [-f] a.log | qps a.log b.log *.log" exit 1 fi . lgq_config.sh if [ $1 = "-f" ]; then echo "run real time mod : like ‘tail -f‘ " tail -f $2 | grep $ff | awk ‘{print $3}‘ | uniq -c fi for((i=1;i<=$#;i++));do file_list="$file_list ${!i}" done echo $file_list | xargs cat | grep $ff | awk ‘{print $3}‘ | uniq -c | awk ‘{n++;all+=$1}END{print "avg query per secon d : "all/n}‘
3,日志格式
NOTICE: 05-15 09:01:38: phone_normal * 10061 [ logid:50837222 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:哈尔滨市. phone:0451-57982263 error:OK result:(0451)57982263 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10051 [ logid:50837224 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:上海市. phone:021-57150725 error:OK result:(021)57150725 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10064 [ logid:50837225 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:长春市. phone:0431-87613255 error:OK result:(0431)87613255 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10048 [ logid:50837223 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:长春市. phone:0431-87970378 error:OK result:(0431)87970378 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10063 [ logid:50837227 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:鹤壁市. phone:0392-3316991 error:OK result:(0392)3316991 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10058 [ logid:50837226 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:长春市. phone:0431-87096667 error:OK result:(0431)87096667 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10057 [ logid:50837229 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:长春市. phone:0431-87961042 error:OK result:(0431)87961042 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10050 [ logid:50837228 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:深圳市. phone:0755-25689693 error:OK result:(0755)25689693 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10060 [ logid:50837232 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:长春市. phone:0431-85771613 error:OK result:(0431)85771613 ][ ] NOTICE: 05-15 09:01:38: phone_normal * 10059 [ logid:50837231 ][ proctime:total:0(ms) queue:0+rev:0+proc:0+write:0 ][ reqip:10.48.31.106 ][ re qsvr:mcpack_press ][ cmdno: ][ svrname:query ][ errno: ][ ][ city.area:上海市. phone:021-34711765 error:OK result:(021)34711765 ][ ]
原文:http://www.cnblogs.com/bobodeboke/p/3759363.html