No Analytics, No Problem – Go Old School with IIS Log Parsing

Log Parser is a powerful little tool that allows you to write SQL-like queries against your IIS log files. (I somewhat think this was a base for Powershell, but maybe that’s just me). You can download Log Parser from Microsoft.

Below are a few Log Parser scripts that I occasionally use on my own website(s) for double checking hit counts, page views, and top IIS errors occurring in the web application.

This is by far only a tiny sample of what you can do with Log Parser and those of you who are data mining fanatics, you can go nuts compiling information against your IIS log files! Have fun!

Don’t forget to change the path to point to your log file(s) directory for the website/web application you are analyzing.

Get hit count on web-resources:

LOGPARSER “SELECT COUNT(*) as [Count], cs-uri-stem, sc-status from ‘c:\mylogpath\ex*.log’ WHERE sc-status <> 200 GROUP BY cs-uri-stem, sc-status ORDER BY [Count] DESC” -rtp:-1 -o:datagrid

Get page view count on webpages:

LOGPARSER “SELECT Date, COUNT (*) AS PAGEVIEWS FROM ‘c:\mylogpath\ex*.log’ WHERE EXTRACT_EXTENSION(to_lowercase(cs-uri-stem)) NOT IN (‘asf’;’axd’;’css’;’exe’;’gif’;’ico’;’jpg’;’js’;’msi’;’png’;’txt’;’vsi’;’wmv’;’xml’;’zip’) and sc-status=200 Group By Date” -rtp:-1 -o:datagrid

Get unique visitors (by ip address):

logparser “SELECT DISTINCT date, c-ip INTO ‘c:\mylogpath\Temporary.txt’ FROM ‘C:\Program Files\Log Parser 2.2\web_logs\ex*.log'” -o:w3c
logparser “SELECT date, count(c-ip) FROM ‘c:\mylogpath\Temporary.txt’ GROUP BY date” -i:w3c -o:datagrid

Get top IIS errors occurring on website/webapplication:

LOGPARSER “SELECT COUNT(*) as [Count], cs-uri-stem, sc-status from ‘c:\mylogpath\ex*.log’ WHERE sc-status <> 200 GROUP BY cs-uri-stem, sc-status ORDER BY [Count] DESC” -rtp:-1 -o:datagrid

For security-related information on using Log Parser check out this great article from Security Focus.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s