Skip to content

Instantly share code, notes, and snippets.

@falzm
Created July 30, 2013 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falzm/6116747 to your computer and use it in GitHub Desktop.
Save falzm/6116747 to your computer and use it in GitHub Desktop.
A poor man's NCSA log analyzer written in (G)AWK
# My first GAWK script
{
total_bytes += $10
}
$9 ~ /2[0-9]+/ {
n_sc_2xx++
}
$9 ~ /3[0-9]+/ {
n_sc_3xx++
}
$9 ~ /4[0-9]+/ {
n_sc_4xx++
}
$9 ~ /5[0-9]+/ {
n_sc_5xx++
}
END {
printf "%d requests served:\n", NR
printf " 2XX=%d (%.2f%%)\n 3XX=%d (%.2f%%)\n 4XX=%d (%.2f%%)\n 5XX=%d (%.2f%%)\n",
n_sc_2xx, (n_sc_2xx/NR) * 100,
n_sc_3xx, (n_sc_3xx/NR) * 100,
n_sc_4xx, (n_sc_4xx/NR) * 100,
n_sc_5xx, (n_sc_5xx/NR) * 100
printf "%d bytes sent\n", total_bytes
}
@falzm
Copy link
Author

falzm commented Jul 30, 2013

Example usage:

 awk -f ./ncsa_stats.awk /var/log/nginx/*-access.log
 1574 requests served:
   2XX=1288 (81.83%)
   3XX=117 (7.43%)
   4XX=152 (9.66%)
   5XX=0 (0.00%)
 28498436 bytes sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment