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