Table of Contents

Nginx Parser using Bash Commands

  cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -rn | head -5


   386056 200
   236410 500
   30743 404
    6182 301
    3621 304

Lets store this output in a bash variable

top5_requests_by_error_code=$(cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -rn | head -5)
echo "$top5_requests_by_error_code" | xclip

Finding timeout requests is very critical, and if there are too many timeout requests, It mean your server is either serving more than usual number of requests or something wrong with the server.

  #find out number of timeout requests
  no_of_timeout_requests=$(egrep 'Connection timed out' error.log | wc -l)

Another important category is to find out number of broken links which are in most demand. here is an example of finding most requested URLs...

  top_20_most_requested_broken_links=$(awk '($9 ~ /404/)' access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -20)




Related Posts