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

注意

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

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

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

您可以透過上述任何方法來:

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

必要條件

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

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

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

  3. 選取 [Azure Application Insights]>[下一步]

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

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

  6. 選取 [完成]

注意

如需完整指示 (包括如何不使用 Visual Studio 而直接在 ASP.NET Core 應用程式上啟用 Application Insights),請參閱適用於 ASP.NET Core 應用程式的 Application Insights

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

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

  2. 選取 [Microsoft.ApplicationInsights.AspNetCore]

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

  4. 選取更新

    Screenshot that shows where to select the Application Insights package for update.

啟用分析工具

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

  • 在 ASP.NET Core 應用程式中,使用 Azure Resource Manager 範本和 Visual Studio。 建議
  • 藉由 Azure CLI 使用 PowerShell 命令。
  • 藉由使用 Azure 資源總管。

安裝 Azure 診斷擴充功能

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

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

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

  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。

下一步