使用 Application Insights 探查实时 Azure 应用服务应用Profile live Azure App Service apps with Application Insights

可以在使用基本服务层级或更高层级的 Azure 应用服务上运行的 ASP.NET 和 ASP.NET Core 应用中运行 Profiler。You can run Profiler on ASP.NET and ASP.NET Core apps that are running on Azure App Service using Basic service tier or higher.

为应用启用 ProfilerEnable Profiler for your app

若要为应用启用 Profiler,请遵循下面的说明。To enable Profiler for an app, follow the instructions below. 如果你在运行另一种类型的 Azure 服务,则下面提供了用于在其他受支持平台上启用 Profiler 的说明:If you're running a different type of Azure service, here are instructions for enabling Profiler on other supported platforms:

Application Insights Profiler 是作为应用服务运行时的一部分预先安装的。Application Insights Profiler is pre-installed as part of the App Services runtime. 下面的步骤将说明如何为应用服务启用它。The steps below will show you how to enable it for your App Service. 即使在生成时已在应用程序中包含了 App Insights SDK,也应该执行这些步骤。Follow these steps even if you've included the App Insights SDK in your application at build time.

备注

Application Insights Profiler 的无代码安装遵循 .NET Core 支持策略。Codeless installation of Application Insights Profiler follows the .NET Core support policy. 若要详细了解受支持的运行时,请参阅 .NET Core 支持策略For more information about supported runtimes, see .NET Core Support Policy.

  1. 导航到应用服务的 Azure 控制面板。Navigate to the Azure control panel for your App Service.

  2. 为应用服务启用“Always On”设置。Enable "Always On" setting for your app service. 可以在“配置”页的“设置”下找到此设置(请参阅下一步中的屏幕截图),然后选择“常规设置”选项卡 。You can find this setting under Settings, Configuration page (see screenshot in the next step), and select the General settings tab.

  3. 导航到“设置”>“Application Insights”页面。Navigate to Settings > Application Insights page.

    在应用服务门户上启用 App Insights

  4. 按窗格中的说明创建新资源,或者选择现有的 App Insights 资源,以便监视应用。Either follow the instructions on the pane to create a new resource or select an existing App Insights resource to monitor your app. 此外,请确保 Profiler 已启用。Also make sure the Profiler is On. 如果 Application Insights 资源位于与应用服务不同的订阅中,则无法使用此页来配置 Application Insights。If your Application Insights resource is in a different subscription from your App Service, you can't use this page to configure Application Insights. 你仍然可以通过手动创建所需的应用设置来手动执行此操作。You can still do it manually though by creating the necessary app settings manually. 下一部分包含有关手动启用 Profiler 的说明。The next section contains instructions for manually enabling Profiler.

    添加 App Insights 站点扩展

  5. 现已使用应用服务应用设置启用了 Profiler。Profiler is now enabled using an App Services App Setting.

    Profiler 的应用设置

手动或使用 Azure 资源管理器启用 ProfilerEnable Profiler manually or with Azure Resource Manager

可以通过为 Azure 应用服务创建应用设置来启用 Application Insights Profiler。Application Insights Profiler can be enabled by creating app settings for your Azure App Service. 包含如上所示选项的页面将为你创建这些应用设置。The page with the options shown above creates these app settings for you. 但是,也可以使用模板或其他方式自动创建这些设置。But you can automate the creation of these settings using a template or other means. 如果 Application Insights 资源与 Azure 应用服务位于不同的订阅中,这些设置也将起作用。These settings will also work if your Application Insights resource is in a different subscription from your Azure App Service. 下面是启用 Profiler 所需的设置:Here are the settings needed to enable the profiler:

应用设置App Setting Value
APPINSIGHTS_INSTRUMENTATIONKEYAPPINSIGHTS_INSTRUMENTATIONKEY Application Insights 资源的 iKeyiKey for your Application Insights resource
APPINSIGHTS_PROFILERFEATURE_VERSIONAPPINSIGHTS_PROFILERFEATURE_VERSION 1.0.01.0.0
DiagnosticServices_EXTENSION_VERSIONDiagnosticServices_EXTENSION_VERSION ~3~3

可以使用 Azure 资源管理器模板Azure PowerShellAzure CLI 设置这些值。You can set these values using Azure Resource Manager Templates, Azure PowerShell, Azure CLI.

为中国云启用 ProfilerEnable Profiler for china cloud

如果要为中国云启用 Profiler,可以使用以下应用设置。If you want to enable the profiler for china cloud, you can use the below app settings.

应用设置App Setting 中国云China Cloud
ApplicationInsightsProfilerEndpointApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.cn
ApplicationInsightsEndpointApplicationInsightsEndpoint https://dc.applicationinsights.azure.cn

禁用 ProfilerDisable Profiler

若要为单个应用实例停止或重启 Profiler,请在左侧边栏上选择“WebJobs”,然后停止名为 ApplicationInsightsProfiler3 的 Web 作业。To stop or restart Profiler for an individual app's instance, on the left sidebar, select WebJobs and stop the webjob named ApplicationInsightsProfiler3.

禁用针对 Web 作业的 Profiler

建议在所有应用上都启用 Profiler,以便尽早发现任何性能问题。We recommend that you have Profiler enabled on all your apps to discover any performance issues as early as possible.

使用 WebDeploy 将更改部署到 Web 应用程序时可能会删除 Profiler 的文件。Profiler's files can be deleted when using WebDeploy to deploy changes to your web application. 可以通过在部署期间排除 App_Data 文件夹的删除来防止发生这种删除。You can prevent the deletion by excluding the App_Data folder from being deleted during deployment.

后续步骤Next steps