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.

5
  • What version of IIS are you running? IIS 7 has built-in features for this. Commented Dec 16, 2011 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). Commented Dec 16, 2011 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) Commented Sep 16, 2013 at 18:27
  • See also stackoverflow.com/a/12983284/12597 Commented Sep 16, 2013 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. Commented Sep 16, 2013 at 21:17

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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.
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.
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.

1 Comment

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?
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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.