This is old news for most developers, but I'm throwing it out there anyway. I've known
about Microsoft's LogParser for a long time now, but today is the first time I've actually
used it.
I needed to get some quick stats about the usage of some WCF services from an IIS log of an application recently put into production. I downloaded
LogParser 2.2, googled and found
some examples, experimented with some queries, and within 2 hours had a batch file that was creating two simple text file reports that would quickly tell you about service usage.
Here's the batch file contents I created:
@echo off
if "%1" == "" goto reqparam
@echo on
@echo * Getting total hits per service into %1_ServiceHits.txt
"C:\Program Files\Log Parser 2.2\logparser.exe" -i:iisw3c "SELECT DISTINCT
cs-uri-stem AS Url, COUNT(*) AS Hits INTO %1_ServiceHits.txt FROM %1 WHERE
(cs-uri-stem LIKE '%%.svc') GROUP BY Url ORDER BY Hits DESC" -o:NAT -rtp:-1
@echo * Getting hits per hour into %1_HitsPerHour.txt
"C:\Program Files\Log Parser 2.2\logparser.exe" -i:iisw3c "SELECT date,
QUANTIZE(time, 3600) AS Hour, cs-uri-stem AS Url, COUNT(*) AS Hits INTO
%1_HitsPerHour.txt FROM %1 WHERE (cs-uri-stem LIKE '%%.svc') GROUP BY date,
Hour, Url ORDER BY date, Hour, URL" -o:NAT -rtp:-1
@echo off
goto end
:reqparam
@echo Missing Parameter - IIS log filename
:end
And here's an example of the output:
Url Hits
------------------------- ------
/AwesomeService.svc 208862
/SweetService.svc 133267
/GoodService.svc 41577
/MundaneService.svc 41271
/HappyService.svc 10300
/CrappyService.svc 2950
Just for fun, here's a command that will create a pie chart.
"C:\Program Files\Log Parser 2.2\logparser.exe" -i:iisw3c "SELECT DISTINCT
cs-uri-stem AS Url, COUNT(*) AS Hits INTO c:\temp\iisreport.gif FROM
c:\temp\ex070730.log WHERE (cs-uri-stem LIKE '%.svc') GROUP BY Url ORDER BY Hits
DESC" -chartType:PieExploded3D -chartTitle:"Service Hits"
Which generated this image:

Its a little bit ugly because of the values put in front of the chart, but it wasn't worth it to me to spend the time figuring out which command line option would turn that off.
* PS - I've noticed that the
unofficial website for LogParser seems to be down. Bummer.
Labels: tools