使用 Application Insights 來分析即時 Azure App Service 應用程式Profile live Azure App Service apps with Application Insights

您可以執行 Profiler 在 ASP.NET 和 ASP.NET Core 應用程式正在 Azure App Service 上使用基本服務層或更高版本。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. 下列步驟將示範如何啟用您的 App Service。The steps below will show you how to enable it for your App Service. 即使您已經包含應用程式的 application Insights SDK 的應用程式在建置階段中,請遵循下列步驟。Follow these steps even if you've included the App Insights SDK in your application at build time.

  1. 啟用 「 永遠開啟 」 設定您的 app service。Enable "Always On" setting for your app service. 您可以更新您的 App Service,[一般設定] 下的 [組態] 頁面中的設定。You can update the setting in the Configuration page of your App Service under General Settings.

  2. 移至 Azure 入口網站中的 [App Service] 窗格。Go to the App Services pane in the Azure portal.

  3. 瀏覽至 [設定] > [Application Insights] 窗格。Navigate to Settings > Application Insights pane.

    在 App Service 入口網站上啟用 Application 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 資源位於不同的訂用帳戶,從您的 App Service,您無法使用此頁面來設定 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. 現在已使用 App Service 應用程式設定來啟用 Profiler。Profiler is now enabled using an App Services App Setting.

    Profiler 的應用程式設定

啟用 Profiler,以手動方式或使用 Azure Resource ManagerEnable Profiler manually or with Azure Resource Manager

建立您的 Azure App Service 應用程式設定,可以啟用 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 App Service,這些設定也會運作。These settings will also work if your Application Insights resource is in a different subscription from your Azure App Service. 以下是啟用分析工具所需的設定: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 Resource Manager 範本Azure PowershellAzure CLIYou can set these values using Azure Resource Manager Templates, Azure Powershell, Azure CLI.

其他雲端中以手動方式啟用 ProfilerEnabling Profiler for other clouds manually

如果您想要啟用其他雲端的分析工具,您可以使用下列應用程式設定。If you want to enable the profiler for other clouds, you can use the below app settings.

應用程式設定App Setting 美國政府值US Government Values 中國雲端China Cloud
ApplicationInsightsProfilerEndpointApplicationInsightsProfilerEndpoint https://agent.serviceprofiler.azure.us https://profiler.applicationinsights.azure.cn
ApplicationInsightsEndpointApplicationInsightsEndpoint https://dc.applicationinsights.us https://dc.applicationinsights.azure.cn

停用 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