你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

对 Application Insights Profiler 进行故障排除

本文提供了帮助你使用 Application Insights Profiler 的故障排除步骤和信息。

是否使用了适当的 Profiler 终结点?

目前唯一需要修改终结点的区域是 Azure 政府由世纪互联运行的 Microsoft Azure

应用设置 美国政府云 中国云
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.us https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.us https://dc.applicationinsights.azure.cn

应用是否在正确的版本上运行?

高于 .NET Framework 4.6.2 的版本支持 Profiler。

如果 Web 应用是 ASP.NET Core 应用程序,则必须在支持的最新 ASP.NET Core 运行时上运行。

是否使用了正确的 Azure 服务计划?

免费或共享应用服务计划当前不支持 Profiler。 请升级到 Profiler 可开始工作的某一基本计划。

注意

不支持 Azure Functions 消耗计划。 请参阅使用 Application Insights 探查实时 Azure Functions 应用

是否在正确的时间范围内搜索 Profiler 数据?

如果要查看的数据的期限超过两周,请尝试限制时间筛选器并重试。 七天后将删除跟踪。

是否可以访问网关?

请检查防火墙或代理是否未阻止你访问此网页

是否看到超时,或是否需要检查以查看探查器是否正在运行?

但是,仅当可将分析数据附加到运行 Profiler 期间所发生的请求时,才会上传分析数据。 Profiler 每小时会收集两分钟的数据。 还可以通过启动分析会话来触发 Profiler。

Profiler 将跟踪消息和自定义事件写入到 Application Insights 资源。 可以使用这些事件来查看 Profiler 的运行方式。

搜索由 Profiler 发送到 Application Insights 资源的跟踪消息和自定义事件。

  1. 在 Application Insights 资源中,从顶部菜单中选择“搜索”。

    Screenshot that shows selecting the Search button from the Application Insights resource.

  2. 使用以下搜索字符串查找相关数据:

    stopprofiler OR startprofiler OR upload OR ServiceProfilerSample
    

    Screenshot that shows the search results from aforementioned search string.

    上面的搜索结果包含两个 AI 资源的两个搜索示例:

    • 如果在 Profiler 运行时应用程序未收到请求,则消息会说明由于没有活动而取消上传。

    • Profiler 已启动,并在检测到它运行期间发生的请求时发送了自定义事件。 如果显示了 ServiceProfilerSample 自定义事件,则表示已捕获某个配置文件,并且该配置文件显示在“Application Insights 性能”窗格中。

    如果未显示任何记录,则表示 Profiler 并未运行或已超时。请确保已在 Azure 服务上启用探查器

并行线程的重复计数

当两个或多个并行线程与请求相关联时,堆栈查看器中的总时间指标可能大于请求的持续时间。 在这种情况下,总线程时间就会超过实际已用时间。

例如,一个线程可能会等待另一个线程完成。 查看器会尝试检测此情况并省略不相关的等待时间。 这样,它会倾向于显示过多信息,而不是省略关键信息。

如果看到跟踪中出现并行线程,请确定哪些线程处于等待状态,以便可以查明请求的热路径。 通常情况下,快速进入等待状态的线程等待其他线程完成。 请专注于其他线程,忽略等待中线程花费的时间。

排查特定 Azure 服务上的 Profiler 问题

以下部分将引导你完成在 Azure 应用服务或 Azure 云服务上使用 Profiler 的故障排除步骤。

Azure 应用服务

要使 Profiler 正常工作,请确保:

  • Web 应用已启用 Application Insights 并具有正确的设置

  • ApplicationInsightsProfiler3 WebJob 正在运行。 若要检查 webjob:

    1. 转到 Kudu。 在 Azure 门户中:

      1. 在应用服务实例中,在左侧窗格中选择“高级工具”。
      2. 选择“转到”。
    2. 在顶部菜单中,选择“工具”>“WebJob”仪表板。 “WebJobs”窗格随即打开。

      如果 ApplicationInsightsProfiler3 未显示,请重启应用服务应用程序。

      Screenshot that shows the WebJobs pane, which displays the name, status, and last runtime of jobs.

    3. 若要查看 WebJob 的详细信息(包括日志),请选择“ApplicationInsightsProfiler3”链接。 “连续 WebJob 详细信息”窗格随即打开。

      Screenshot that shows the Continuous WebJob Details pane.

如果 Profiler 仍然无法正常工作,可以下载日志并提交 Azure 支持票证

查看诊断服务站点扩展的状态页

如果 Profiler 是通过门户中的 Application Insights 窗格启用的,则它是由诊断服务站点扩展启用的。 可以转到 https://{site-name}.scm.azurewebsites.net/DiagnosticServices 来查看此扩展的状态页。

注意

状态页链接的域因云而异。 此域与应用服务的 Kudu 管理站点相同。

此状态页显示 Profiler 和 Snapshot Debugger 代理的安装状态。 如果出现意外错误,则会显示该错误以及如何修复它的步骤。

你可以使用应用服务的 Kudu 管理站点获取此状态页的基 URL:

  1. 在 Azure 门户中,打开应用服务应用程序。
  2. 选择“高级工具”
  3. 选择“转到”。
  4. 在 Kudu 管理站点上:
    1. /DiagnosticServices 附加到该 URL。
    2. 选择 Enter。

其结尾类似于 https://<kudu-url>/DiagnosticServices

状态页显示类似于以下示例。

Screenshot that shows the Diagnostic Services status page.

注意

Application Insights Profiler 的无代码安装遵循 .NET Core 支持策略。 若要详细了解支持的运行时,请参阅 .Net Core 支持策略

手动安装

配置 Profiler 时,将对 Web 应用的设置进行更新。 如有必要,可以手动应用更新

活动分析会话太多

最多可以为同一服务计划中运行的四个 Web 应用启用 Profiler。 如果超过四个,Profiler 可能会引发以下错误:

Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException

若要解决此问题,请将一些 Web 应用移到其他服务计划中。

部署错误:目录不为空“D:\home\site\wwwroot\App_Data\jobs”

如果在已启用 Profiler 的情况下将 Web 应用重新部署到 Web 应用资源,可能会看到如下消息:

“目录不为空 'D:\home\site\wwwroot\App_Data\jobs'”

如果通过脚本或通过 Azure Pipelines 运行 Web 部署,则会发生此错误。 解决方法是将以下部署参数添加到 Web 部署任务:

-skip:Directory='.*\\App_Data\\jobs\\continuous\\ApplicationInsightsProfiler.*' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs\\continuous$' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs$'  -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data$'

这些参数将删除 Application Insights Profiler 所用的文件夹,并取消阻止重新部署进程。 它们不影响当前运行的 Profiler 实例。

Application Insights Profiler 是否正在运行?

Profiler 在 Web 应用中以连续 WebJob 的形式运行。 可以在 Azure 门户中打开 Web 应用资源。 在“WebJobs”窗格中,查看 ApplicationInsightsProfiler 的状态 。 如果探查器未运行,请打开“日志”获取详细信息。

VM 和 Azure 云服务

查看 Azure 诊断是否正确配置了 Profiler:

  1. 验证所部署的 Azure 诊断配置的内容是否符合你的预期。

  2. 确保 Azure 诊断在 Profiler 命令行上传递正确的 iKey。

  3. 检查 Profiler 日志文件,以查看 Profiler 是否已运行但返回了错误。

若要检查用于配置 Azure 诊断的设置:

  1. 登录到虚拟机 (VM)。

  2. 在此位置打开日志文件。 此插件版本在你的计算机上可能会更高。

    对于 VM:

    c:\WindowsAzure\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log
    

    对于 Azure 云服务:

    c:\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log
    
  3. 在该文件中,搜索字符串 WadCfg,找到传递给 VM 用于配置 Azure 诊断的设置。

  4. 检查 Profiler 接收器使用的 iKey 是否正确。

  5. 检查用于启动 Profiler 的命令行。 用于启动 Profiler 的参数位于以下文件中(驱动器可以是 c:d:,目录可能已隐藏):

    对于 VM:

    C:\ProgramData\ApplicationInsightsProfiler\config.json
    

    对于 Azure 云服务:

    D:\ProgramData\ApplicationInsightsProfiler\config.json
    
  6. 确保 Profiler 命令行中的 iKey 是正确的。

  7. 使用上述 config.json 文件中找到的路径,检查 Profiler 日志文件 BootstrapN.log。 其中显示:

    • 表示 Profiler 正在使用的设置的调试信息。
    • 来自 Profiler 的状态和错误消息。

    可在以下位置找到文件:

    对于 VM:

    C:\WindowsAzure\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    

    对于 Azure 云服务:

    C:\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    
  8. 如果当应用程序接收请求时 Profiler 正在运行,则会显示以下消息:“检测到来自 iKey 的活动”。

  9. 上传跟踪时,会显示以下消息:“开始上传跟踪”。

编辑网络代理或防火墙规则

如果应用程序通过代理或防火墙连接到 Internet,则可能需要更新规则才能与 Profiler 通信。

Application Insights Profiler 使用的 IP 包含在 Azure Monitor 服务标记中。 有关详细信息,请参阅服务标记文档

支持

如果仍需要帮助,请在 Azure 门户中提交支持票证。 请包含错误消息中的相关 ID。