Created
December 27, 2013 06:56
-
-
Save clodio/8143563 to your computer and use it in GitHub Desktop.
Awk script to analyse apache log to find bottleneck
This file contains hidden or 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 | |
| #command line to analyse apache log to get most consuming ressources | |
| ## Configure apache log | |
| ### Apache log format must be changed | |
| #- %D is added to get service time in microsecondes | |
| #- separator | is used in apache log to facilitate the analysis (awk -F"|") | |
| ### Change configuration in your vhost or apache configuration | |
| # LogFormat "%h|%{X-Forwarded-For}i|%t|%v|%p|%r|%>s|%b|%D" customlogtime | |
| # CustomLog /var/log/apache2/access.log customlogtime | |
| # adjustement needed to match your business case | |
| # change the 26 value (length of the url) | |
| # change the sed value (don't take into account queryr parameters that change too much) | |
| # change the grep value (to include or exclude patterns) | |
| echo -e " Page TotalServiceTime NbCalls AverageServicetime" | |
| cat /var/log/apache2/access.log | grep -v 'images' | sed 's/POST/POS/g' |sed 's/DELETE/DEL/g' | sed 's/\/v1\//\/v1*** /g'| awk -F'|' '{ key=substr($6,6,26); tot[key]+=$9; cpt[key]++; } END { for (key in tot) printf("%20s %14d %14d %14d\n", key, tot[key], cpt[key], tot[key]/cpt[key]); }' | sort -k2n | tail -50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment