3 ms·
One I used to use when website performance seemed bad. Prints out hits in the current log with a count for each unique client ip: awk '{print $1}' < apache.
by tyingq 6y ago
One I used to use when website performance seemed bad. Prints out hits in the current log with a count for each unique client ip:
awk '{print $1}' < apache.log | sort -n | uniq -c | sort -rn |less
Produces output like:
4482 66.249.73.135
3264 46.105.14.53
3157 130.237.218.86
2073 75.97.9.59
1013 50.16.19.13
...
And fairly easy to throw in a "grep" for specific fetched urls, slices of time, etc.
- gmuslera 6y agoI use cut instead of awk, at least for logs like apache or ones with fixed amount of spaces between fields, because it means less parsing/work, specially for summarizing long log files. Also use cat of the log as input, because is the same pattern for zcat/grep/zgrep if the input is compressed or I did some selection of records before. Some of the records you may have to search could have the port attached (i.e. output of netstat, haproxy logs or others) so for stripping them I add rev | cut -d ":" -f 2- | rev on the list of IPs to not get messed up with IPv6 records.