2

What I'm looking for is some way to monitor the page_load of every page in the system to work out how long between the request and the end of the data being sent back to the user is.

I'm looking to do this 100% server side, and I don't want to make any code changes to the application code. If application code changes would be required, is there a standard place to make these? I'm thinking some kind of web.config type parameter that will log the information to a location/database. We can do the processing part, just need the raw data somehow.

The information I'd be looking to gather is:

  1. Page name (including query string)
  2. DateTime of the request
  3. The amount of time it took
  4. Any additional information about the request that we can get our hands on!

Obviously, the pre-requisite is that it shouldn't impact performance.

I'm also looking for either something low cost, or a methodology that we can develop our system with.

Additional Information: To be clearer, we have full control of the IIS and underlying operating system, however, the website application is outside of our control. We can change configuration files, but not actual code of the application.

We're using IIS 6.0 currently, however, if this kind of thing is more efficient, and/or works out of the box, with IIS 7.0/7.5 then it may speed up the move to this so happy to hear about those suggestions.

Martin
  • 2,180
  • 4
  • 21
  • 41
  • What version of IIS are you running? IIS 7 has built-in features for this. – John Saunders Dec 16 '11 at 17:12
  • 6.0 currently, however we're looking at upgrading to 7.5 at some point, so information 7 features would be useful (although not considered the answer to this question, sorry). – Martin Dec 16 '11 at 18:48
  • @JohnSaunders Can you point out where in IIS7 the page statistics are? i cannot find any such thing (in IIS 7.5, Windows Server 2008 R2) – Ian Boyd Sep 16 '13 at 18:27
  • See also http://stackoverflow.com/a/12983284/12597 – Ian Boyd Sep 16 '13 at 20:16
  • I know this sort of data is available with failed request tracing. I believe you can define what constitutes "failed" so that you can get this information for all requests. There's certainly a lot more possible than that. – John Saunders Sep 16 '13 at 21:17

4 Answers4

3

This isn't a WebForms concern, it's an ASP.net concern. Using either global.asax, or an IHttpModule hook into the BeginRequest/EndRequest events to track how long a request takes.

StopWatchModule.cs

class StopWatchModule: IHttpModule
{
    private Int64 _requestStartTicks; 

    public void Init(HttpApplication application)
    {
         application.Context.BeginRequest += Application_BeginRequest;
         application.Context.EndRequest += Application_EndRequest;
    }

    private void Application_BeginRequest(object sender, EventArgs e)
    {
        _requestStartTicks = Stopwatch.GetTimestamp();
    }

    private void Application_EndRequest(object sender, EventArgs e)
    {
        Int64 requestStopTicks = Stopwatch.GetTimestamp();

        Double requestDurationMs = (Double)(requestStopTicks - _requestStartTicks) / Stopwatch.Frequency / 1000000f; 
        /* 
           Sample output:
           Request for "~/EditCustomer.aspx" took 37 ms to complete
        */
        HttpContext context = ((HttpApplication)sender).Context;
        Logger.Info("Request for \"{0}\" to {1} ms to complete", 
              context.Request.AppRelativeCurrentExecutionFilePath, 
              requestDurationMs.ToString("r", CultureInfo.InvariantCulture));
    }
}

Web.config

<configuration>
    <system.web>
        <httpModules>
            <add name="StopWatchModule" type="StopWatchModule" />
        </httpModules>
    </system.web>
</configuration>

I'm writing from memory so there may be errors above, but that's the idea. your log message can be as detailed as you want. and Logger is some type of logging library. I prefer log4net, but the choice is yours.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Jason Meckley
  • 7,589
  • 1
  • 24
  • 45
  • where would performance sit with this, is it out of line from the request itself? would this affect the actual requests that are happening? Also, what is the life of the context, is it a single page? I am assuming that I should be able to get hold of the session information as well? – Martin Dec 16 '11 at 18:46
  • I'#m marking this as the answer as it was the way we decided to go, even though I didn't get a reply from the author. – Martin Dec 21 '11 at 09:19
  • this is inline with the request itself and you have access to the entire context. request, response, session, etc. for more information on how this fits into the structure of your application research the asp.net pipeline. this the core of all http development in .net. webforms, mvc, etc is all built on top of the asp.net pipeline. – Jason Meckley Dec 21 '11 at 13:25
1

Can you touch global.asax? You can override Application events there for when a request is received, completed, failed, etc.

Depending on what all you need you might also try parsing IIS logs since you can add some performance metrics to that.

n8wrl
  • 19,439
  • 4
  • 63
  • 103
  • providing that the application code doesn't need to be recompiled then yes, are there any links you can provide and how to accomplish this? – Martin Dec 16 '11 at 18:38
0

What I'm looking for is some way to monitor the page_load of every page in the system to work out how long between the request and the end of the data being sent back to the user is.

I wonder if the IIS logs' time-taken field can be of any use since it will provide you with time, IP, bytes (sent/received), etc.

See fields for additional information

Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81
0

You can always enable tracing in your web.config, with the options pageOutput = "false".

You can then go to trace.axd to view information for a specific request.

You can also do this for a specific page by setting it in your @page directive.

AaronS
  • 7,649
  • 5
  • 30
  • 56