配置 Application Insights ProfilerConfigure Application Insights Profiler

更新的 Profiler 代理Updated Profiler Agent

触发器功能仅适用于版本 2.6 或更高版本的 Profiler 代理。The trigger features only work with version 2.6 or newer of the profiler agent. 如果运行的是 Azure 应用服务,代理将自动更新。If you are running an Azure App Service, your agent will be updated automatically. 如果转到网站的 Kudu URL 并将 \DiagnosticServices 追加到其末尾(类似于 https://yourwebsite.scm.chinacloudsites.cn/diagnosticservices),则可以查看正在运行的代理版本。You can see what version of the agent you are running if you go to the Kudu URL for your website and append \DiagnosticServices to the end of it, like this: https://yourwebsite.scm.chinacloudsites.cn/diagnosticservices. Application Insights Profiler Webjob 应为版本 2.6 或更高版本。The Application Insights Profiler Webjob should version 2.6 or newer. 可以通过重启 Web 应用来强制升级。You can force an upgrade by restarting your web app.

如果在 VM 或云服务上运行探查器,则需要安装 Azure 诊断 (WAD) 扩展版本 16.0.4 或更高版本。If you are running the profiler on a VM or Cloud Service, you need to have Azure Diagnostics (WAD) extension version 16.0.4 or newer installed. 可以通过登录到 VM 并查看以下目录来检查 WAD 的版本:C:\Packages\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.16.0.4。You can check the version of WAD by logging onto your VM and looking this directory: C:\Packages\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.16.0.4. 目录名称即为安装的 WAD 版本。The directory name is the version of WAD that is installed. 有新版本可用时,Azure VM 代理会自动更新 WAD。The Azure VM agent will update WAD automatically when new versions are available.

Profiler 设置页Profiler settings page

若要打开 Azure Application Insights Profiler 设置窗格,请转到“Application Insights 性能”窗格,然后选择“配置 Profiler”按钮。To open the Azure Application Insights Profiler settings pane, go to the Application Insights Performance pane, and then select the Configure Profiler button.

用于打开 Profiler 设置页的链接

此时会打开如下所示的页面:That opens a page that looks like this:

Profiler 设置页

“配置 Application Insights Profiler”页包含以下功能:The Configure Application Insights Profiler page has these features:

功能Feature 说明Description
立即探查Profile Now 启动与此 Application Insights 实例链接的所有应用的分析会话。Starts profiling sessions for all apps that are linked to this instance of Application Insights.
触发器Triggers 用于配置使 Profiler 运行的触发器。Allows you to configure triggers that cause the profiler to run.
最近的探查会话Recent profiling sessions 显示有关最近分析会话的信息。Displays information about past profiling sessions.

立即探查Profile Now

使用此选项可以按需启动探查会话。This option allows you to start a profiling session on demand. 单击此链接时,向此 Application Insights 实例发送数据的所有 Profiler 代理将开始捕获探查数据。When you click this link, all profiler agents that are sending data to this Application Insights instance will start to capture a profile. 5 到 10 分钟后,探查会话将显示在下面的列表中。After 5 to 10 minutes, the profile session will show in the list below.

用户若要手动触发 Profiler 会话,他们至少需要对其 Application Insights 组件角色具有“写入”访问权限。For a user to manually trigger a profiler session, they require at minimum "write" access on their role for the Application Insights component. 在大多数情况下,可以自动获得此访问权限,不需要额外的工作。In most cases, you get this access automatically and no additional work is needed. 如果遇到问题,则要添加的订阅范围角色将是“Application Insights 组件参与者”角色。If you're having issues, the subscription scope role to add would be the "Application Insights Component Contributor" role. 详细了解如何使用 Azure 监视进行角色访问控制See more about role access control with Azure Monitoring.

触发器设置Trigger Settings

触发器设置浮出控件

单击菜单栏上的“触发器”按钮会打开“触发器设置”框。Clicking the Triggers button on the menu bar opens the trigger settings box. 可将触发器设置为在 CPU 或内存使用百分比达到设置的级别时启动探查。You can set up trigger to start profiling when the percentage of CPU or Memory use hits the level you set.

设置Setting 说明Description
开/关按钮On / Off Button 开:Profiler 可由此触发器启动;关:探查器不会由此触发器启动。On: profiler can be started by this trigger; Off: profiler won't be started by this trigger.
内存阈值Memory threshold 内存使用率达到此百分比时,将启动 Profiler。When this percentage of memory is in use, the profiler will be started.
持续时间Duration 设置 Profiler 在触发后要运行的时间长短。Sets the length of time the profiler will run when triggered.
冷却Cooldown 设置 Profiler 在触发后,再次检查内存或 CPU 使用率之前所要等待的时间长短。Sets the length of time the profiler will wait before checking for the memory or CPU usage again after it's triggered.

最近的探查会话Recent Profiling Sessions

此页面部分显示有关最近建立的探查会话的信息。This section of the page shows information about recent profiling sessions. 探查会话代表 Profiler 代理探查托管应用程序的某台计算机的时间段。A profiling session represents the period of time when the profiler agent was taking a profile on one of the machines hosting your application. 单击其中一个行可从会话打开探查数据。You can open the profiles from a session by clicking on one of the rows. 对于每个会话,此部分会显示:For each session, we show:

设置Setting 说明Description
触发者Triggered by 会话的启动方式:由触发器启动、由“立即探查”操作启动,或由默认采样启动。How the session was started, either by a trigger, Profile Now, or default sampling.
应用程序名称App Name 已探查的应用程序的名称。Name of the application that was profiled.
计算机实例Machine Instance 运行 Profiler 代理的计算机的名称。Name of the machine the profiler agent ran on.
TimestampTimestamp 捕获探查数据的时间。Time when the profile was captured.
受跟踪者Tracee 附加到各个请求的跟踪数。Number of traces that were attached to individual requests.
CPU %CPU % Profiler 运行时使用的 CPU 百分比。Percentage of CPU that was being used while the profiler was running.
内存百分比Memory % Profiler 运行时使用的内存百分比。Percentage of memory that was being used while the profiler was running.

使用 Web 性能测试生成发往应用程序的流量Use web performance tests to generate traffic to your application

只需单击一下,即可手动触发 Profiler。You can trigger Profiler manually with a single click. 假设要运行 Web 性能测试。Suppose you're running a web performance test. 需要借助跟踪来了解 Web 应用在承受负载情况下的运行性能。You'll need traces to help you understand how your web app is running under load. 控制何时捕获跟踪至关重要,因为知道负载测试何时将运行。Having control over when traces are captured is crucial, because you know when the load test will be running. 但是随机采样间隔可能会错过捕获。But the random sampling interval might miss it.

下一部分将说明此方案的工作原理:The next sections illustrate how this scenario works:

步骤 1:通过启动 Web 性能测试生成发往 Web 应用的流量Step 1: Generate traffic to your web app by starting a web performance test

如果 Web 应用已有传入流量或者你就是希望手动生成流量,请跳过本部分并转到步骤 2。If your web app already has incoming traffic or if you just want to manually generate traffic, skip this section and continue to Step 2.

  1. 在 Application Insights 门户中,选择“配置” > “性能测试” 。In the Application Insights portal, select Configure > Performance Testing .

  2. 若要启动新的性能测试,请选择“新建”按钮。To start a new performance test, select the New button.

    创建新的性能测试

  3. 在“新建性能测试”窗格中,配置测试目标 URL。In the New performance test pane, configure the test target URL. 接受所有默认设置,然后选择“运行测试”开始运行负载测试。Accept all default settings, and then select Run test to start running the load test.

    配置负载测试

    新测试的状态最先为“已排队”,随后状态变为“正在进行”。The new test is queued first, followed by a status of in progress .

    负载测试已提交并排队

    负载测试正在运行中

步骤 2:启动 Profiler 按需会话Step 2: Start a Profiler on-demand session

  1. 负载测试运行时,启动 Profiler 以在 Web 应用接收负载期间捕获该应用上的跟踪。When the load test is running, start Profiler to capture traces on the web app while it's receiving load.

  2. 转到“配置 Profiler”窗格。Go to the Configure Profiler pane.

步骤 3:查看跟踪Step 3: View traces

在 Profiler 完成运行后,按照通知中的说明转到“性能”窗格并查看跟踪。After Profiler finishes running, follow the instructions on notification to go to Performance pane and view traces.

后续步骤Next steps

启用 Profiler 并查看跟踪Enable Profiler and view traces