Awk web log analysis (page execution time) (common applications 3)

Source: Internet
Author: User
Today, we mainly talk about analyzing logs through awk to quickly get the execution time. The performance and efficiency are greatly improved compared with the previous article.

Some time ago, I wrote an article about how to use shell scripts to analyze the most frequently accessed and time-consuming pages (slow queries) of nginx logs, which mentioned the importance of time-consuming page analysis. Today, we mainly talk about analyzing logs through awk to quickly get the execution time. The performance and efficiency are greatly improved compared with the previous article!

I. web log file format


Copy codeThe code is as follows:
222.83.181.42--[09/Oct/2010: 04: 04: 03 + 0800] GET/pages/international/tejia. php HTTP/1.1 "200" 15708 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Sicent; WoShiHoney. B ;. net clr 2.0.50727 ;. net clr 3.0.20.6.2152 ;. net clr 3.5.30729) "-" 0.037

If they are separated by spaces, the last field [0.037] is the page execution time, and the second field is the page access address.

II. execute code


Copy codeThe code is as follows:
Awk 'In in {
Print "Enter log file :";
Getline logs;
# Logs = "/var/log/nginx/access. log-20101008 ";
OFMT = "%. 3f ";

While (getline <logs)
{
Split ($7, atmp ,"? ");
AListNum [atmp [1] + = 1;
AListTime [atmp [1] + = $ NF;
Ilen ++;
}
Close (logs );
Print "\ r \ ntotal:", ilen, "\ r \ n ======================================== ===\ r \ n ";
For (k in aListNum)
{
Print k, aListNum [k], aListTime [k]/aListNum [k] | "sort-r-n-k3 ";
}

}'

Result:



Performance:



422780 logs. the statistical completion speed is about 5 seconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.