Original address: http://xuqq999.blog.51cto.com/3357083/774714
Apache Log analysis can get a lot of useful information, now to try the most basic, get the most access to the top 10 IP address and number of visits.
Since it is statistical, awk is essential, useful and efficient.
The command is as follows:
awk ' {a[$1] + = 1;} END {for (I in a) printf ("%d%s\n", a[i], i);} ' log file | Sort-n | Tail
First, you use awk to get a list, then sort it out, and finally use tail to take the last 10.
The above parameters can be slightly modified to display more data, such as the tail plus-n parameters, and other log format commands may need to be modified.
the most frequently joined IP addresses in the current Web server
#netstat-ntu |awk ' {print $} ' |sort | uniq-c| Sort-nr
View the top 10 most visited IPs in a log
#cat access_log |cut-d '-F 1 | Sort |uniq-c | Sort-nr | awk ' {print $} ' | Head-n 10 | Less
See more than 100 IPs in the log
#cat access_log |cut-d '-F 1 | Sort |uniq-c | awk ' {if (>) Print $ |SORT-NR | Less
View the most recently accessed files
#cat Access_log | tail-10000 | awk ' {print $7} ' | Sort | uniq-c | Sort-nr | Less
View pages that have been accessed more than 100 times in the log
#cat Access_log | Cut-d '-F 7 | Sort |uniq-c | awk ' {if (>) print $} ' | Less
Statistics a URL, the number of visits per day
#cat Access_log | grep ' 12/aug/2009 ' | grep '/images/index/e1.gif ' | WC | awk ' {print '} '
Most visited pages in the first five days
#cat Access_log | awk ' {print $7} ' | uniq-c | Sort-n-R | Head-20
See what the IP is doing in the log.
#cat Access_log | grep 218.66.36.119 | awk ' {print ' \ t ' $7} ' | Sort | uniq-c | Sort-nr | Less
List files that have been transmitted for longer than 30 seconds
#cat Access_log | awk ' ($NF >) {print $7} ' | Sort-n | uniq-c | Sort-nr | Head-20
List the most time-consuming pages (more than 60 seconds)
#cat Access_log | awk ' ($NF > && $7~/\. php/) {print $7} ' | Sort-n | uniq-c | Sort-nr | head-100
Linux analytics logs get the top 10 IP for most accesses