- 论坛徽章:
- 1
|
本帖最后由 shreychen 于 2014-06-17 17:07 编辑
最近需要分析nginx日志,尝试了下awk脚本,求推荐awk学习资料,网上的比较零散- #!/usr/bin/awk -f
- BEGIN{
- FS="^A";
- }
- {
- httpcode[$5]++;
- if ($5 != 200){
- split($11,upstreams,", ");
- for (key in upstreams){
- ups=upstreams[key];
- upstream[ups]++;
- }
- }
- }
- END{
- for (code in httpcode) print httpcode[code],code;
- for (ups in upsteam) print upsteam[ups],ups;
- }
复制代码 for (ups in upsteam) print upsteam[ups],ups; 不明白这个为啥没起作用
nginx日志样本- 16/Jun/2014:09:53:40 +0800^A192.168.0.44^A-^AGET /search?dtype=news&duid=bd4d7010aee44b1b&tid=desc&q=0 HTTP/1.1^A200^A34080^A-^AMozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)^A-^A0.016^A192.168.201.90:8888^A0.016
- 16/Jun/2014:09:53:40 +0800^A192.168.0.44^A-^AGET /search?dtype=pubnote&duid=10b91cc33c6d74a2&tid=desc&q=0 HTTP/1.1^A200^A2123^A-^AMozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)^A-^A0.013^A192.168.201.87:8888^A0.013
- 16/Jun/2014:09:53:40 +0800^A192.168.0.55^A-^APOST /cm?type=dynamicdict HTTP/1.1^A200^A126^A-^AJakarta Commons-HttpClient/3.1^A-^A0.005^A192.168.201.191:19850, 192.168.201.192:19850^A0.100, 0.005
- 16/Jun/2014:09:53:40 +0800^A192.168.0.53^A-^APOST /search HTTP/1.1^A200^A5950^A-^AJakarta Commons-HttpClient/3.1^A-^A0.143
- ^A192.168.201.87:8888^A0.143
复制代码 |
|