1. Nginx status monitoring Nginx provides a built-in status information monitoring page that can be used to monitor the overall access status of Nginx. This function is implemented by the ngx_http_stub_status_module module. Use the nginx -V 2>&1 | grep -o with-http_stub_status_module command to check whether the current Nginx has the status function. If the output is ngx_http_stub_status_module, it means that it has the status function. If not, you can add this module during compilation. By default, status is disabled, we need to enable it and specify the uri to access the data. server { listen 80; server_name default_server; location /status { stub_status on; allow 114.247.125.227; } } The allow configuration only allows the specified IP to access the nginx status function. If it is removed, there is no restriction. After restarting Nginx, visit http://{IP}/status in your browser to view status monitoring information.
After collecting Nginx data, you can use monitoring tools to monitor it. 2. Log analysis Nginx default log format configuration can be found in /etc/nginx/nginx.conf log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time'; Printed log example
Common analysis commands 1. Count UV based on access IP awk '{print $1}' paycenteraccess.log | sort -n | uniq | wc -l 2. Query the most frequently visited IPs (top 10) awk '{print $1}' /var/log/nginx/access.log | sort -n | uniq -c | sort -rn | head -n 10 3. Check the IP access volume in a certain period of time (1-8 o'clock) awk '$4 >="[25/Mar/2020:01:00:00" && $4 <="[25/Mar/2020:08:00:00"' /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr |wc -l 4. View IP addresses that have visited more than 100 times awk '{print $1}' /var/log/nginx/access.log | sort -n |uniq -c |awk '{if($1 >100) print $0}'|sort -rn 5. View the URLs and number of visits visited by the specified IP grep "39.105.67.140" /var/log/nginx/access.log|awk '{print $7}' |sort |uniq -c |sort -n -k 1 -r 6. Count PV based on visited URLs cat /var/log/nginx/access.log |awk '{print $7}' |wc -l 7. Query the most frequently visited URLs (top 10) awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -n 10 8. View the most frequently visited URLs ([excluding /api/appid]) (top 10) grep -v '/api/appid' /var/log/nginx/access.log|awk '{print $7}' | sort |uniq -c | sort -rn | head -n 10 9. View pages with more than 100 page visits cat /var/log/nginx/access.log | cut -d ' ' -f 7 | sort |uniq -c | awk '{if ($1 > 100) print $0}' | less 10. View the most recent 1,000 records and the most visited pages tail -1000 /var/log/nginx/access.log |awk '{print $7}'|sort|uniq -c|sort -nr|less 11. Count the number of requests per hour and the time points of the top 10 (accurate to the hour) awk '{print $4}' /var/log/nginx/access.log |cut -c 14-15|sort|uniq -c|sort -nr|head -n 10 12. Count the number of requests per minute and the time points of the top 10 (accurate to the minute) awk '{print $4}' /var/log/nginx/access.log |cut -c 14-18|sort|uniq -c|sort -nr|head -n 10 13. Count the number of requests per second and the time points of the top 10 (accurate to seconds) awk '{print $4}' /var/log/nginx/access.log |cut -c 14-21|sort|uniq -c|sort -nr|head -n 10 14. Find logs for a specified time period awk '$4 >="[25/Mar/2020:01:00:00" && $4 <="[25/Mar/2020:08:00:00"' /var/log/nginx/access.log 15. List the URLs whose transmission time exceeds 0.6 seconds, and display the first 10 cat /var/log/nginx/access.log |awk '(substr($NF,2,5) > 0.6){print $4,$7,substr($NF,2,5)}' | awk -F '"' '{print $1,$2,$3}' |sort -k3 -rn | head -10 16. List the time points where the request time for /api/appid exceeds 0.6 seconds cat /var/log/nginx/access.log |awk '(substr($NF,2,5) > 0.6 && $7~/\/api\/appid/){print $4,$7,substr($NF,2,5)}' | awk -F '"' '{print $1,$2,$3}' |sort -k3 -rn | head -10 17. Get the top 10 most time-consuming request times, URLs, and durations cat /var/log/nginx/access.log |awk '{print $4,$7,substr($NF,2,5)}' | awk -F '"' '{print $1,$2,$3}' | sort -k3 -rn | head -10 Summarize This is the end of this article about Nginx status monitoring and log analysis. For more relevant Nginx status monitoring and log analysis content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The easiest way to reset mysql root password
>>: Let you understand the working principle of JavaScript
Today I used docker to pull the image, but the sp...
Table of contents The effect of mixed inheritance...
Overview Nginx load balancing provides upstream s...
When using TensorFlow for deep learning, insuffic...
Install Docker on CentOS 8 Official documentation...
Table of contents 1. Problems encountered 2. Anal...
mysql query control statements Field deduplicatio...
Quickly modify the table structure of a MySQL tab...
1. Unzip MySQL 8.0.16 The dada folder and my.ini ...
Preface: How to get the coordinates of the curren...
The Internet is an organism that is constantly ev...
Toy Story 3 Online Marketing Website Zen Mobile I...
The official document states: By injecting the ro...
This article lists some tips and codes about form...
The cause is that the process opens a number of f...