Skip to main content

Posts

Showing posts from March, 2019

What would log(s) say - Part 1: Find requests by HTTP status code

As the title suggests, this will be a multi part post. I hope you find the series useful. The idea for this post and blog originated when i posted a possible quick solution in an internal forum. 2 people reached out saying that i should document it. Since i keep on experimenting with such stuff, why not share that in the form of the blog .   Trivia: The post title is a inspired by a common Hindi saying "Log Kya Kahenge". Yes. Pun intended. Today's solution: from the access logs, get list of URLs resulting in an error and sort them by most frequent to least frequent.   awk '{if($9>400) { print $9 "\t" $7}}' access.log* | cut -d '?' -f1 | sort -k2 | uniq -c | sort -nr Explanation: Scan through all the access.log in the folder and look for requests with status code is above 400. The idea is to catch only the errors like 404, 500 etc.  With awk we only print the status code ($9) and the PATH which is broken ($7). With cut, we get rid of