Created
October 10, 2017 13:07
-
-
Save bwangelme/4d9b56904ba774403bc5acc79458f392 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# Author: bwangel<[email protected]> | |
# Date:Oct,10,2017 14:16 | |
LOG_FILE="./2017_10_10uwsgi-webapp.log" | |
echo "" | awk ' | |
END { | |
FMT = "%-33s\t%-5s\t%-15s%-10s\n" | |
printf(FMT, "url", "count", "total-time(ms)", "average-time(ms)") | |
}' | |
cat ${LOG_FILE} | egrep '^{address' | awk ' | |
function get_timestamp(datetime_fmt) { | |
split(datetime_fmt, datetime_group, " ") | |
year = datetime_group[4] | |
month = sprintf("%02d",(match("JanFebMarAprMayJunJulAugSepOctNovDec",datetime_group[1])+2)/3) | |
day = datetime_group[2] | |
split(datetime_group[3], time, ":") | |
hour = time[1] | |
minute = time[2] | |
second = time[3] | |
timestamp = mktime(sprintf("%s %s %s %s %s %s", year, month, day, hour, minute, second)) | |
return timestamp | |
} | |
BEGIN { | |
total = 0 | |
max_timestamp = 0 | |
min_timestamp = 99999999999 | |
} | |
{ | |
timestamp = get_timestamp(sprintf("%s %s %s %s", $22, $23, $24, substr($25, 1, length($25) - 1))) | |
if (timestamp > max_timestamp) { | |
max_timestamp = timestamp | |
} | |
if (timestamp < min_timestamp) { | |
min_timestamp = timestamp | |
# print(timestamp, NR) | |
} | |
split($27, query_url, "?") | |
url_count[query_url[1]] += 1 | |
url_time[query_url[1]] += $33 | |
total += 1 | |
} | |
END { | |
FMT = "%-33s\t%-5s\t%-15s%-10s\n" | |
for (url in url_count) | |
printf(FMT, url, url_count[url], url_time[url], url_time[url] / url_count[url]) | |
print("日志开始时间:", strftime("%Y-%m-%d %H:%M:%S", min_timestamp)) | |
print("日志结束时间:", strftime("%Y-%m-%d %H:%M:%S", max_timestamp)) | |
print("total:", total) | |
} | |
' | sort -n -r -t' ' -k 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment