Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx is widely used in both high-traffic websites and small personal blogs. In actual production environments, the analysis of Nginx logs helps us understand the access situation of the website, find potential problems and optimize them. This article will implement a comprehensive statistical analysis of Nginx logs by writing a Shell script. Nginx log formatFirst, we need to make sure that the Nginx log format is similar to the following: Assume that our log file is called access.log. Shell script implementationNext, we write a Shell script to perform statistical analysis on Nginx logs. This script includes the following functions:
Script code implementation: 1. Count the number of various status codes: ① Arry[$12] += 1;:
② total++;:
③ for (s in Arry):
④ printf "%d\t%.4f\t%s\n", Arry[s], Arry[s] / total, s:
Running the above command will produce the following output: Count the number of various status codes 2. Count the most visited Referers After executing the above command, the output is as shown below: Count the most visited Referers 3. Count the most visited URIs After executing the above command, the output is as shown below: Count the most visited URIs 4. Count the most visited IP and User-Agent(1) Count the number of IP visits After executing the above command, the output is as shown below: Count the number of IP visits (2) Count the most visited User-Agents After executing the above command, the output is as shown below: Statistics visit Statistics visit 5. Statistics on the number of requests per minute, traffic, request time, status code, etc. After executing the above command, the following results are output: SummarizeThrough the above Shell script, we can quickly and comprehensively analyze Nginx logs to understand the website's access and performance. This not only helps us find potential problems, but also provides strong data support for subsequent optimization work. In actual applications, you can further expand and customize this script according to your needs. How to obtain the scriptThe above scripts have been uploaded to gitee. You can get them if you need them. The repository on gitee mainly shares some commonly used scripts in work. You can frok or watch the repository so that you can pay attention to updates in time. Script Repository Warehouse address: https://gitee.com/didiplus/script |
>>: 7.2 Our computer room is disconnected from the Internet! What should I do?
Hosteons tested the Hybrid Servers (VDS) product ...
At present, the number of 4G users in my country ...
RAKsmart has launched its cloud server for about ...
"No one needs 6G. The industry should make 6...
With a loud bang, the data center collapsed The d...
Part 01 Semantic Communication Technology The rap...
iWebFusion (or iWFHosting) is a long-established ...
When these three words are mentioned, do many peo...
ExtraVM recently launched a new VPS host in the N...
DMIT.io is a foreign hosting company founded in 2...
As of the end of 2020, 718,000 5G base stations h...
The "2019 World Telecommunication and Inform...
[[342618]] This article is reprinted from the WeC...
Some operators have already started running befor...
Continue from the previous article "Introduc...