-
-
Save tkuchiki/66f89cf0eaf0e3727d81 to your computer and use it in GitHub Desktop.
nginx ltsv sort & request count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_format ltsv 'host:$remote_addr\t' | |
'user:$remote_user\t' | |
'time:$time_iso8601\t' | |
'method:$request_method\t' | |
'uri:$request_uri\t' | |
'protocol:$server_protocol\t' | |
'status:$status\t' | |
'size:$body_bytes_sent\t' | |
'request_time:$request_time\t' | |
'upstream_response_time:$upstream_response_time\t' | |
'upstream_addr:$upstream_addr\t' | |
'referer:$http_referer\t' | |
'user_agent:$http_user_agent\t'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# リクエストカウント | |
cat access.log | awk '{ print $5 }' | sed 's/upstream_response_time://g' | sed 's/uri://g' | sed 's/time://g' | sed 's/?.*//g' | sort -n | uniq -c | |
## 時間を範囲指定して出力 | |
START_TIME=`date -d "2013-09-27 14:59:59" "+%Y%m%d%H%M%S"`; END_TIME=`date -d "2013-09-27 14:59:59" "+%Y%m%d%H%M%S"`; cat access.log | awk '{ print $3, $5 }' | sed 's/request_time://g' | sed 's/upstream_response_time://g' | sed 's/uri://g' | sed 's/time://g' | sed 's/?.*//g' | awk '{time=$1; gsub(/[:T+\-]|09:00/, "", time);} '"$START_TIME"' <= time && time <= '"$END_TIME"' { print $2 }' | sort -n | uniq -c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## レスポンスタイムが指定秒数を超えたものを表示 | |
### $3 ($1) : time (レスポンスを返した時間) | |
### $10 ($2) : レスポンスタイム | |
### $5 ($3) : URL | |
#### レスポンスタイム降順 | |
cat access.log | awk '{ print $3, $10, $5 }' | sed 's/upstream_response_time://g' | sed 's/uri://g' | sed 's/time://g' | sed 's/?.*//g' | awk '$2 >= 0.5 { printf "%s \t %f \t %s\n", $1, $2, $3 }' | sort -nr -k 2 | |
## 時間を範囲指定して出力 | |
### $4 ($1) : time (レスポンスを返した時間) | |
### $10 ($2) : リクエストタイム | |
### $11 ($3) : レスポンスタイム | |
### $6 ($4) : URL | |
START_TIME=`date -d "2013-09-27 14:59:59" "+%Y%m%d%H%M%S"`; END_TIME=`date -d "2013-09-27 14:59:59" "+%Y%m%d%H%M%S"`; cat access.log | awk '{ print $3, $9, $10, $5 }' | sed 's/request_time://g' | sed 's/upstream_response_time://g' | sed 's/uri://g' | sed 's/time://g' | sed 's/?.*//g' | awk '{time=$1; gsub(/[:T+\-]|09:00/, "", time);} '"$START_TIME"' <= time && time <= '"$END_TIME"' { printf "%s \t %f \t %f \t %s\n", $1, $2, $3, $4 }' | sort -nr -k 2 | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment