(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Log Parser script: Percent of status codes across all hits/requests

Note: This article was written using Log Parser 2.2. Therefore, while it may work for a different version, it may not.

The following SQL can be used by Log Parser to generate a chart with the total requests (for a day, month, or year) and what percent each status code is of those requests. An example chart can be found at the end of this article.

First, I assume that the below is put in the same directory as the logs you would like to parse. 

SELECT sc-status AS [HTTP Status Code], count(*) AS Requests
INTO http_status_percent_graph-%date%.png
FROM ex%date%*.log
GROUP BY [HTTP Status Code]
ORDER BY Requests DESC

Once you've saved this, you can call the script like such, so long as you're already in the directory you saved the SQL file.

logparser file:http_status_percent_graph.sql?date=0710 -o:chart -chartType:Pie -chartTitle:"Status as Percent of Requests"

If you just want the numbers, you can use the following SQL.

SELECT sc-status, count(*)
INTO http_status_codes-%date%.txt
FROM ex%date%*.log
GROUP BY sc-status
ORDER BY sc-status

It too can be called via the command line (again, assuming you save the SQL file and run the following in the same directory as your log files).

logparser -rtp:-1 file:http_status_codes.sql?date=0710 

Feel free to modify the scripts to your own need.

Example chart

Example of the status code chart
Example of the status code chart

blog comments powered by Disqus

Archives