Shell parsing HTTP Logs

Source: Internet
Author: User
Tags month name

HTTP status Code
1 header----information, the server receives the request, requires the requestor to continue to perform the operation
2 Word Header----Successful, the operation was successfully received and processed
3 Word Header----Redirect, further action required to complete the request
4 Word Header----Client error, request contains syntax error or cannot complete request
5 Word Header----Server error, the server has an error while processing the request

Apply Log parsing scripts

Cat/usr/local/nginx/logs/access.log | awk ' {print '} ' | Sort | uniq-c | Sort-rn

Sort
Options and Parameters:
-F: Ignores case differences, such as a and a are treated as encodings;
-B: Ignores the first whitespace part;
-M: Sort by month name, such as JAN, DEC and so on;
-N: Sort using "pure number" (by default it is sorted by text type);
-R: Reverse sort;
-U: Is Uniq, in the same data, only one row is represented;
-T: delimiter, the default is to use the [tab] key to separate;
K: The meaning of sorting by that interval (field)

Uniq
Options and Parameters:
-I: Ignoring the difference between uppercase and lowercase characters;
-C: Counting
-U: only display unique rows

Extracting Status Codes
Cat/usr/local/nginx/logs/access.log | awk ' {print $9} '

Extracting the information you want
Cat/usr/local/nginx/logs/access.log | Grep-ioe "http\/1\. [1|0]\ "[[: Blank:]][0-9]{3}"

grep parameters in a detailed
-I ignores case
-O to output only the portion of the file that matches
-E for precise
Special symbols represent meaning
[: Alnum:] representing English-size letters and numbers, i.e. 0-9, A-Z, A-Z
[: Alpha:] on behalf of any English-size writing section, i.e. A-Z, A-Z
[: Blank:] represents both the blank key and the [Tab] key
[: Cntrl:] represents the control keys above the keyboard, which includes CR, LF, Tab, Del. Wait a minute
[:d Igit:] stands for numbers, i.e. 0-9
[: Graph:] All other keys except blank bytes (blank key and [Tab] key)
[: Lower:] represents the lowercase section, i.e. A-Z
[:p rint:] represents any byte that can be printed out
[:p UNCT:] represents punctuation (punctuation symbol), i.e.: "'?!; : # $...
[: Upper:] represents uppercase bytes, i.e. A-Z
[: space:] Any bytes that generate whitespace, including blank keys, [Tab], CR, etc.
[: Xdigit:] Represents a numeric type of 16 digits, so includes: 0-9, A-f, a-f number and byte

Shell parsing HTTP logs

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.