awk脚本分析日志

Posted yanpan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了awk脚本分析日志相关的知识,希望对你有一定的参考价值。

#######################统计日志中测试人员执行用例个#############################
 
技术图片
 
BEGIN{
printf "%-10s%-10s ","Tester","TotalTestcases"
}
{
USERS[$4] += 1
}
END{
for(u in USERS)
printf "%-10s%-10d ",u,USERS[u]
}
 
awk -f test.awk log.txt
技术图片

 

 

 
#############################################################################
 
######################分别统计每位测试人员执行用例成功和失败的总数################
技术图片

 

 

BEGIN{
printf "%-10s%-10s%-10s ","Tester","PassTotal","FailTotal"
}
{
if ($5 == "Pass")
{
SUCCESS[$4] += 1
}else{
FAIL[$4] += 1
}
USERS[$4] += 1
}
END{
for(u in USERS)
printf "%-10s%-10s%-10s ",u,SUCCESS[u],FAIL[u]
}
 
awk -f test.awk log.txt
技术图片

 

 

 
#############################################################################
 
#####################分别统计每位测试人员执行用例CRITICAL、ERROR日志等级数以及所有测试人员每项总数################
技术图片

 

 

BEGIN{
printf "%-10s %-10s %-10s %-10s %-10s ","Tester","ErrorTotlal","CriticalTotal","PassTotal","FailTotal"
}
{
if ($5 == "Pass")
{
SUCCESS[$4] += 1
}else{
FAIL[$4] += 1
}
if ($3 == "ERROR")
{
ERROR[$4] += 1
}
if ($3 == "CRITICAL")
{
CRITICAL[$4] += 1
}
USERS[$4] += 1
}
END{
for(u in USERS)
{
ALL_ERRORS += ERROR[u]
ALL_CRITICALS += CRITICAL[u]
ALL_SUCCESS += SUCCESS[u]
ALL_FAILS += FAIL[u]
printf "%-10s %-10s %-10s %-10s %-10s ",u,ERROR[u],CRITICAL[u],SUCCESS[u],FAIL[u]
}
printf "%-10s %-10s %-10s %-10s %-10s ","Total",ALL_ERRORS,ALL_CRITICALS,ALL_SUCCESS,ALL_FAILS
}
 
awk -f test.awk log.txt
技术图片

 

 

 
#############################################################################

以上是关于awk脚本分析日志的主要内容,如果未能解决你的问题,请参考以下文章

shell分析nginx日志

持续更新—Nginx日志分析方法

Nginx/Apache日志分析脚本

awk日志分析

AWK分析日志

shell 脚本分析nginx 访问日志状态码