您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 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. 目前只有通过此方法才能在 Linux 上启用 Profiler。Enabling Profiler on Linux is currently only possible via this method.

为应用启用 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.

  1. 为你的应用服务启用“Always On”设置。Enable "Always On" setting for your app service. 你可以在应用服务的“配置”页面中在“常规设置”下更新设置。You can update the setting in the Configuration page of your App Service under General Settings.

  2. 转到 Azure 门户中的“应用服务”窗格。Go to the App Services pane in the Azure portal.

  3. 导航到“设置”>“Application Insights”窗格 。Navigate to Settings > Application Insights pane.

    在应用服务门户上启用 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.

禁用 ProfilerDisable Profiler

若要为单个应用实例停止或重启 Profiler,请在“Web 作业”下转到“应用资源” 。To stop or restart Profiler for an individual app's instance, under Web Jobs, go to the app resource. 若要删除 Profiler,请转到“扩展” 。To delete Profiler, go to Extensions.

禁用针对 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