為 Azure 虛擬機器上的 Web 應用程式啟用 Profiler

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要瞭解如何遷移至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 遷移至 Az。

在本文中,您將瞭解如何透過三種不同的方法,在 Azure 虛擬機器上執行 Application Insights Profiler (VM) 或 Azure 虛擬機器擴展集:

  • Visual Stuido 與 Azure Resource Manager
  • PowerShell
  • Azure 資源總管

使用上述任一方法,您可以:

  • 設定 Azure 診斷延伸模組以執行 Profiler。
  • 在 VM 上安裝 Application Insights SDK。
  • 部署應用程式。
  • 透過 Azure 入口網站 中的 Application Insights 實例來檢視分析工具追蹤。

必要條件

將 Application Insights SDK 新增至您的應用程式

  1. 在 Visual Studio 中開啟您的 ASP.NET Core 專案。

  2. 選取 [專案]>[新增 Application Insights 遙測]。

  3. 選取[Azure 應用程式 [深入解析>] [下一步]。

  4. 選取 Application Insights 資源所在的訂用帳戶,然後選取 [ 下一步]。

  5. 選取要儲存連接字串的位置,然後選取 [ 下一步]。

  6. 選取 [完成]。

注意

如需完整指示,包括如何在沒有 Visual Studio 的 ASP.NET Core 應用程式上啟用 Application Insights,請參閱 application Insights for ASP.NET Core 應用程式

確認最新的 Application Insights SDK 穩定版本

  1. 移至 [專案]>[管理 NuGet 套件]。

  2. 選取 [Microsoft.ApplicationInsights.AspNetCore]。

  3. 在側邊窗格中,從下拉式清單中選取最新版本的 SDK。

  4. 選取 [更新]。

    顯示要在哪裡選取 Application Insights 套件以進行更新的螢幕擷取畫面。

啟用分析工具

您可以透過下列三種方式之一來啟用 Profiler:

  • 使用 Azure Resource Manager 範本和 Visual Studio 在您的 ASP.NET Core應用程式中。 推薦。
  • 透過 Azure CLI 使用 PowerShell 命令。
  • 使用 Azure 資源總管。

安裝 Azure 診斷擴充功能

  1. 選擇要使用哪一個 ARM 範本:

  2. 在範本中,找出屬於類型 extension 的資源。

  3. 在 Visual Studio 中,移至 arm.json 您安裝 Application Insights SDK 時所新增 ASP.NET Core應用程式中的 檔案。

  4. 將資源類型 extension 從範本新增至 arm.json 檔案,以使用 Azure 診斷來設定 VM 或虛擬機器擴展集。

  5. WadCfg 標記內,將 Application Insights 檢測金鑰新增至 MyApplicationInsightsProfilerSink

    "WadCfg": {
      "SinksConfig": {
        "Sink": [
          {
            "name": "MyApplicationInsightsProfilerSink",
            "ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY"
          }
        ]
      }
    }        
    
  6. 部署應用程式。

是否可在內部部署伺服器上執行 Profiler?

目前內部部署伺服器不支援 Application Insights Profiler。

下一步