ASP.NET监控page_load性能(无需更改代码)

发布于 2024-12-21 17:34:49 字数 583 浏览 2 评论 0原文

我正在寻找的是某种方法来监视系统中每个页面的 page_load ,以计算出请求与发送回用户的数据结束之间的时间间隔。

我希望做到 100% 服务器端,并且我不想对应用程序代码进行任何代码更改。如果需要更改应用程序代码,是否有一个标准的地方可以进行这些更改?我正在考虑某种 web.config 类型参数,它将信息记录到位置/数据库。我们可以做处理部分,只需要某种方式的原始数据。

我希望收集的信息是:

  1. 页面名称(包括查询字符串)
  2. 请求的日期时间 花费
  3. 的时间
  4. 我们可以掌握的有关请求的任何其他信息!

显然,先决条件是它不应该影响性能。

我也在寻找低成本的东西,或者我们可以用来开发系统的方法。

其他信息: 更清楚地说,我们可以完全控制 IIS 和底层操作系统,但是,网站应用程序不在我们的控制范围内。我们可以更改配置文件,但不能更改应用程序的实际代码。

我们目前使用的是 IIS 6.0,但是,如果这种事情更高效,并且/或可以开箱即用,使用 IIS 7.0/7.5,那么它可能会加快向此方向的迁移,所以很高兴听到这些建议。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

佼人 2024-12-28 17:34:49

这不是 WebForms 问题,而是 ASP.net 问题。使用 global.asaxIHttpModule 挂钩到 BeginRequest/EndRequest 事件来跟踪请求的持续时间需要。

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>

我是凭记忆写的,所以上面可能有错误,但这就是想法。您的日志消息可以根据您的需要详细说明。 Logger 是某种类型的日志库。我更喜欢 log4net,但选择权在你。

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.

末蓝 2024-12-28 17:34:49

你能碰一下global.asax吗?您可以在接收、完成、失败等请求时覆盖应用程序事件。

根据您的需要,您也可以尝试解析 IIS 日志,因为您可以向其中添加一些性能指标。

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.

稳稳的幸福 2024-12-28 17:34:49

您始终可以在 web.config 中使用选项 pageOutput = "false" 启用跟踪。

然后,您可以转到trace.axd 查看特定请求的信息。

您还可以通过在 @page 指令中设置特定页面来执行此操作。

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.

再可℃爱ぅ一点好了 2024-12-28 17:34:49

我正在寻找的是某种方法来监控每个页面的page_load
系统中的页面来计算请求和请求之间的时间
发送回用户的数据结束。

我想知道 IIS 日志的耗时字段是否有任何用处,因为它会为您提供时间、IP、字节(发送/接收)等。

请参阅 字段 了解更多信息

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文