awk statistics time-consuming record section [Maximum, Minimum, average, statistics, ratio, sort]

Source: Internet
Author: User

There is now a time-consuming statistical log of the server-side business logic for filter statistics, formatted as follows


The first column is the keyword, the second and third columns are the other parameters, the fourth column is time-consuming, and I only care about the fourth column.

The goal is to count the time consuming (and the percentage) of the server to find out if there is room for the server to logically optimize.

The first is to take care of the data:

Because this log is not exactly the format shown above, there are a lot of record format is more confusing, so the first thing to do is to exclude irregular format, choose a simple method:

awk ' {if ($2!= ' && $3!= ' && $4!= ' ') {print $NF}} '  Request_cost.log | grep-e ' ^[0-9]+$ ' |
First exclude 2, 3, 4 paragraphs are not worth recording, in the last record of the remaining field, take out the field to ensure that the number

The result of this is that

0
0
0
0
1
0 0 1 1

Next is the statistics and percent:

awk ' {a[$1]++;s+=1}end{for (j in a) printf '%s%.2f%\n ', j,a[j]*100/s} '

So the final instructions are:

awk ' {if ($2!= "&& $3!=" "&& $4!=" ") {print $NF}} ' Request_cost.log | Grep-e "^[0-9]+$" | awk ' {a[$1]++;s+=1}end{for (j in a) printf '%s%.2f%\n ', j,a[j]*100/s} ' > Request_result.log

Output results:


After the output to the file, sort again:

Sort-k 2-gr request_result.log  > Sort_request_result.log
-K 2 refers to the value of the second column as key,-GR is sorted by numeric reverse order

Results:

Time consuming 0ms and 1ms accounted for the vast majority, there is no optimization space.

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.