理论上应该接入小米监控平台. 数据导入,清洗后展示,监控. 目前没有这么一个好的平台.
日志要专项专打. 通过 log logAppender 自动分流到不同的文件中去. 不要手动静态配置了.
日志:
2017-07-14 22:29:00 INFO - [GROUP_GET_SIZE] [ORDER_DRIVER_END_SERVICE_TOPIC@crm_realtime_msg] Stats In One Minute, SUM: 231409 TPS: 3856.82 AVGPT: 1822.12
基本筛选和逐行打印
[loufei@rocketmq-00 otherdays]$ less stats-2017-07-14.0.log
| grep 2017 -m4
| awk -F '- | \\[ | \\] | SUM: | TPS: | AVGPT: '
' {print "2="$2 "3="$3 "4="$4 '
2=3=GROUP_GET_SIZE4= 5=REFUND_KUAIPAY_CALLBACK_SUCCESS_TOPIC@tradegroup6= Stats In One Minute, 7= 0 8= 0.00 9= 0.0010=11=
2=3=GROUP_GET_SIZE4= 5=BLAME_CANCEL_ORDER_BLAME_TOPIC@blameGroup6= Stats In One Minute, 7= 0 8= 0.00 9= 0.0010=11=
2=3=GROUP_GET_SIZE4= 5=ORDER_PASSENGER_CANCEL_TOPIC@marketing_mall_group6= Stats In One Minute, 7= 2386 8= 39.77 9= 397.6710=11=
统计某个时间段,按小时统计:
less stats-2017-07-14.0.log
| grep '2017-07-14 22:'
| awk -F '- | \\[ | \\] | SUM:| TPS:| AVGPT:'
'{ minute=substr($1,12,5); tps[$5"__"minute]+=$8} END { for ( i in tps) print i,tps[i]}'
less ../eagleye.log.full
| grep "|92|"
| awk -F '\\|' ' { sec=substr($2,1,10); if ( $2 > 1582522740000 && $2 < 1582522800000 ) { apiNum[$5"_"sec]+=1;apiCost[$5"_"sec]+=$9 }}
END{
for(i in apiNum) {
if ( apiCost[i] > 50000 ) {print i,apiNum[i],apiCost[i] }
}
}'
int函数,字符串转数字. 秒级,分钟级统计. 时间戳转换.
less ../eagleye.log.full
| grep "|92|"
| awk -F '\\|' ' { sec=int(int($2)/1000); if ( $2 > 1582522620000 && $2 < 1582522920000 ) { apiNum[$5"_"sec]+=1;apiCost[$5"_"sec]+=$9 }}
END
{ for(i in apiNum) { if ( apiCost[i] > 10000 ) {split(i,keys,"_");print i,keys[2],strftime("%c",int(keys[2])),apiNum[i],apiCost[i]/1000 }}}'
变量直接create和引用; END 必须得大写, && 与 if 中的 ( 和逻辑要空格
排序:
less service-access.log
| awk -F '\001'
'{ if( num[$7] < $8 ){ num[$7]=$8}} END{for(i in num ){ print i,num[i]}} '
| sort -k 2
输出结果:
k 是key的意思