Awk analyzes the interface response time in the nginx log

Source: Internet
Author: User

Recently, a customer responded to the client card. The boss gathered a meeting of technical staff to discuss the cause of the slow response, which resulted in Analysis of nginx response time. Because the nginx log format in the online environment is enclosed in quotation marks, processing is a little troublesome. The following is the processing process.

I. nginx log format

Log_format main '$ remote_addr-$ remote_user [$ time_iso8601] "$ request "'
'$ Status $ body_bytes_sent' $ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "'
'$ Upstream_addr' $ upstream_status '$ request_time "';

Ii. nginx access logs(/Var/log/nginx)

12.124.127.44--[29/JUL/2014: 20: 54: 20 + 0800] "Get/HTTP/1.1" 200 211 "-" "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; win64; x64; Trident/5.0) ""-"127.0.0.1: 8081" "200" "0.001"
115.29.113.101--[29/JUL/2014: 20: 54: 22 + 0800] "Get/HTTP/1.1" 200 211 "-" "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; win64; x64; Trident/5.0) ""-"127.0.0.1: 8081" "200" "0.005"
112.124.127.53--[29/JUL/2014: 20: 56: 49 + 0800] "Get/HTTP/1.1" 200 211 "-" "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; win64; x64; Trident/5.0) ""-"127.0.0.1: 8081" "200" "0.002"
112.124.127.44--[29/JUL/2014: 20: 59: 20 + 0800] "Get/HTTP/1.1" 200 211 "-" "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; win64; x64; Trident/5.0) ""-"127.0.0.1: 8081" "200" "0.002"
115.29.113.101--[29/JUL/2014: 20: 59: 22 + 0800] "Get/HTTP/1.1" 200 211 "-" "Mozilla/5.0 (compatible; MSIE 9.0; windows NT 6.1; win64; x64; Trident/5.0) ""-"127.0.0.1: 8081" "200" "0.002"

Iii. nginx Log Analysis

3.1 print response time and remove quotation marks

Cat website. Access. log | awk '{print $ (NF)}' | awk-f "\" '{print $2'}> a.txt

3.2 Merge files and refill the time

Paste-D "website. Access. Log a.txt> B .txt

3.3 search for URLs with a response time greater than 1 second

Cat B .txt | awk '($ NF> 1) {print $6 $7 "$ NF}'> c.txt

The result is as follows:

Statement:This article uses the BY-NC-SA protocol for authorization. Reprinted please note from: awk analysis nginx log interface Response Time Label: awk, Cat, nginx

Awk analyzes the interface response time in the nginx log

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.