When the server pressure is relatively large, it is very laborious to run. We often do site page optimization, we will find those pages with more visits and more time-consuming. Find those addresses that are highly visited and time-consuming, and you'll get immediate results with immediate optimization. Below is a shell script that I often use when doing optimization. This can also be counted as a slow page of the web page's slowpage, like mysql slowquery.
The following is mine: nginx configuration
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';
access_log /var/log/nginx/access.log main buffer=32k;
Configure from above, you can see: ip In the first column, the page time is in the last column, separated by spaces. So in awk, you can use :$1$NF to read the current value. Where NF is a constant, representing the entire number of columns.
The following is the shell file for analyzing the code, which can be saved as slow.sh
#!/bin/sh
export PATH=/usr/Bin:/bin:/usr/local/bin:/usr/X11R6/bin;export LANG=zh_CN.GB2312;
function usage(){echo "$0 filelog options";exit 1;}< Br>
function slowlog(){#set -x;field=$2;files=$1;end=2;msg="";
[[ $2 == '1' ]] && field=1&&end=2&&msg="Total Visits Statistics";[[ $2 == '2' ]] && field=3&&end=4& ;&msg="Average Access Time Statistics";
echo -e "\
\ \
\ ";echo -n "$msg";seq -s '#' 30 |
Sed -e 's/[0-9]*//g';
awk '{split($7,bbb,"?");arr[bbb[1]]=arr[bbb [1]]+$NF; arr2[bbb[1]]=arr2[bbb[1]]+1; } END{for ( i in arr ) { print i":"arr2[i]":" ;arr[i]":"arr[i]/arr2[i]}}' $1 |
Sort -t: +$field -$end -rn |
Grep "pages" |
Head -30 |
Sed 's/:/\\t/g'}
[[ $# < 2 ]] && usage;
slowlog $1 $2;
only Need to execute: slow.sh log file 1 or 2 1: 30 access to the most mundane page 2: 30 access to the most time-consuming page
Execution results are as follows:
chmod + x ./slow.sh
chmod +x slow.sh ./slow.sh /var/log/nginx/./slow.sh /var/log/nginx/access.log 2
Average access time statistics############################################################### 120.456 30.114/pages/########2.php 1 16.161 16.161/pages/########3.php 212 1122.49 5.29475/pages/########4.php 6 28.645 4.77417
..................
I hope the above script will help you.
I. Overview: Adding a program to the Linux kernel requires the following three tasks: 1. Copy the s
Tizen 1.0 was released, and Taize is a Linux-based open source software platform that runs on smartp
The configuration steps of Telnet service are as follows: First, install telnet package (usually tw
Automatically monitor and restart Apache service scripts under Linux
Linux port listener implementation tutorial
Linux/VPS CentOS yum download slow? Install the Axel plugin to speed up the look
Linux input subsystem analysis
How to set static IP address in CentOS 6.2
Linux basic command summary --vi editor
Restart Apache commands under Linux
Detailed explanation of RPM command parameters in Linux
The method of loading ISO files under Linux operating system introduces
How to solve 0x80073cff problem when Win8 installs mail, calendar and contacts
How to open the scanner in win7 system?
Windows 8 store released QQ for win8
Modify the DPI setting method of the login interface of Win 8 system
The Win8 weather app adds a number of useful features
PPLive fault detection common problems and solutions
24 enhanced linux security tips