Skip to content
September 17, 2008 / kiranpatils

How to calculate bandwidth used by website hosted in IIS?

Problem With Solution:

I need to calculate total bandwidth consumed by a website daily which is hosted on IIS. I was thinking to use urchin but can’t make it. Then after some googling I found the way and here it is:

  1. IIS Log files. Stored on

IIS 6.0 and later have request logging enabled by default. The default location for these logs is:

IIS 6.0: %windir%\System32\LogFiles\W3SVC<SiteID>

IIS 7.0: %systemDrive%\Inetpub\logfiles

2. Log Parser 2.2 – A versatile tool by micro. For fetching information from log files [I have used its COM component LogParser.dll]

So you want some reference:

Here are the good links which I would like to share: about configuring Log files. parser tool for download. good article for Log parser introduction. Log file format.,M1Really Great book you must have this [Don’t miss Page # 57] to create program using COM Component. [C#.NET] More on Log parser — PPT

Try to implement it…if don’t make out of it do write me comment I will post my sample project here…so you can quick start….but don’t write comment without trying…it will be good fun!

What other things you can achieve using it..

  • Top browsers accessing your Websites
  • Hits by Hour
  • Request by URI
  • Top 10 Images by Size
  • Top 10 URLs for a website with some interesting data to support you
  • Top 20 clients using your website
  • Status code
  • And you can also generate Charts.




Leave a Comment
  1. Faheem Sial / Mar 27 2009 6:00 am

    Hi Kiran.
    M tryig to do the same thing i want to read the bandwidth of website and ftp traffic i will be very thankfull to u if u send me your sample project as soon as possible (try it on my gmail).I m also googling but only got you where i can see any solution…:)

    • kiranpatils / Apr 1 2009 6:36 am

      Pls check your mail..and below is my code:

      using System;
      using System.Collections.Generic;
      using System.Text;
      using MSUtil;
      namespace BandWidthCalculator
      /// This class will be used to calculate bandwidth
      /// from a IIS Log files using LOG PARSER 2.2
      /// Date: 16-09-2008
      /// Author: Kiran Patil
      class Program
      static void Main(string[] args)
      ILogRecordset rsLP = null;
      ILogRecord rowLP = null;

      LogQueryClassClass LogParser = null;
      COMW3CInputContextClassClass W3Clog = null;

      double UsedBW = 0;
      int Unitsprocessed;

      string strSQL = null;
      LogParser = new LogQueryClassClass();

      W3Clog = new COMW3CInputContextClassClass();
      //W3C Logparsing SQL. Replace this SQL query with whatever
      //you want to retrieve. The example below
      //will sum up all the bandwidth
      Console.WriteLine(@"Please give me path of your log file.(e.g.C:\WINDOWS\system32\LogFiles\W3SVC1\extend1.log)");
      string logfilePath = Console.ReadLine();

      strSQL = @"SELECT SUM(sc-bytes) from C:\WINDOWS\system32\LogFiles\W3SVC1\extend1.log WHERE cs-host like '%local%'";
      // run the query against W3C log
      rsLP = LogParser.Execute(strSQL, W3Clog);
      rowLP = rsLP.getRecord();
      Unitsprocessed = rsLP.inputUnitsProcessed;
      //Bytes to MB Conversion
      double Bytes = Convert.ToDouble(rowLP.getValue(0).ToString());
      UsedBW = Bytes / (1024 * 1024);
      //Round to 3 decimal places
      UsedBW = Math.Round(UsedBW, 5);
      Console.WriteLine("USED BANDWIDTH="+ UsedBW.ToString());
      catch(Exception ex)


  2. Mayank Patel / Oct 13 2010 12:38 pm

    Can you please send me your code as i have same requirement, I tried your pasted code but it gives error. can you please send me complete code by mail.

    I really appreciate your help!!

  3. Please let me know if you’re looking for a writer for your weblog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d love to write some articles for your blog
    in exchange for a link back to mine. Please shoot me an e-mail if interested.
    Many thanks!

    • kiranpatils / Jul 23 2013 1:22 am

      Thanks for appreciation and such a nice offer!

      At this point of time, I’m fine to write. But surely drop you a line, In case, of any help!

      Keep visiting!


  4. Kristian / Jul 31 2013 5:22 am

    Hey there! Do you know if they make any plugins to
    help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results.
    If you know of any please share. Thanks!

Leave a Reply

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

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

Google+ photo

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

Twitter picture

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

Facebook photo

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


Connecting to %s

%d bloggers like this: