對 Application Insights Profiler 進行疑難排解

本文提供讓您使用 Application Insights Profiler 的疑難排解步驟與資訊。

您是否使用適當的 Profiler 端點?

目前,唯一需要端點修改的區域是 Azure Government由 21Vianet 營運的 Microsoft Azure

應用程式設定 美國政府雲端 中國雲端
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.us https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.us https://dc.applicationinsights.azure.cn

您的應用程式是否在正確的版本上執行?

.NET Framework 4.6.2 之後的版本支援 Profiler。

如果 Web 應用程式是 ASP.NET Core 應用程式,則必須在最新版 ASP.NET Core 執行階段上執行。

您是否使用正確的 Azure 服務方案?

免費或共用 App Service 方案目前不支援 Profiler。 升級為其中一個基本方案,讓 Profiler 開始運作。

注意

不支援 Azure Functions 使用量方案。 請參閱使用 Application Insights 來分析即時 Azure Functions 應用程式

您是否在正確的時間範圍內搜尋 Profiler 資料?

如果您嘗試檢視的資料早於兩週,請試著限縮時間篩選條件,然後再試一次。 追蹤會在七天後刪除。

您可以存取閘道嗎?

檢查防火牆或 Proxy 並未封鎖您對此網頁的存取。

您是否看到逾時,或是否需要檢查 Profiler 是否正在執行?

只有在分析資料可附加至 Profiler 執行期間所提出的要求時,才會上傳該資料。 Profiler 每小時會收集一次資料,每次兩分鐘。 您也可以啟動分析工作階段來觸發 Profiler。

Profiler 會將追蹤訊息和自訂事件寫入至您的 Application Insights 資源。 您可以使用這些事件來查看 Profiler 的執行情形。

搜尋 Profiler 傳送給 Application Insights 資源的追蹤訊息和自訂事件。

  1. 在 Application Insights 資源中,從頂端功能表選取 [搜尋]

    Screenshot that shows selecting the Search button from the Application Insights resource.

  2. 使用下列搜尋字串來尋找相關資料:

    stopprofiler OR startprofiler OR upload OR ServiceProfilerSample
    

    Screenshot that shows the search results from aforementioned search string.

    上述搜尋結果包含兩個 AI 資源的搜尋範例:

    • 如果應用程式在 Profiler 執行時未收到要求,會有訊息說明上傳因為沒有活動而取消。

    • Profiler 已啟動,並在偵測到於 Profiler 執行期間有要求提出時傳送自訂事件。 如果顯示 ServiceProfilerSample 自訂事件,則表示已擷取設定檔,並在 [Application Insights 效能] 窗格中提供設定檔。

    如果未顯示任何記錄,表示 Profiler 未執行或逾時。請確定您已在 Azure 服務上啟用 Profiler

平行執行緒重複計算

當兩個以上的平行執行緒與要求相關聯時,堆疊檢視器中的總時間計量可能會超過要求的持續時間。 在此情況下,執行緒的總時間就會超出實際的經過時間。

例如,一個執行緒可能會等候另一個執行緒完成。 檢視器會嘗試偵測這種情況,並省略不重要的等候。 此時,它會寧可顯示過多資訊,以免省略可能具重要性的資訊。

當您在追蹤資料內看到平行執行緒時,請判斷正在等候的執行緒,以便識別要求的最忙碌路徑。 通常,快速進入等候狀態的執行緒會等候其他執行緒。 請專注在其他執行緒上,並忽略等候中執行緒的時間。

針對特定 Azure 服務上的 Profiler 進行疑難排解

下列各節將逐步引導您完成在 Azure App Service 或 Azure 雲端服務上使用 Profiler 的疑難排解步驟。

Azure App Service

若要讓 Profiler 正常運作,請確定:

  • 您的 Web 應用程式已啟用 Application Insights,並使用正確的設定

  • ApplicationInsightsProfiler3 WebJob 正在執行。 若要檢查 WebJob:

    1. 移至 Kudu。 在 Azure 入口網站中:

      1. 在您的 App Service 執行個體中,選取左窗格中的 [進階工具]
      2. 選取 [執行]
    2. 在頂端功能表上,選取 [工具]>[WebJob 儀表板]。 [WebJob] 窗格隨即開啟。

      如果 ApplicationInsightsProfiler3 未顯示,請重新啟動 App Service 應用程式。

      Screenshot that shows the WebJobs pane, which displays the name, status, and last runtime of jobs.

    3. 若要檢視 WebJob 的詳細資料 (包括記錄),請選取 [ApplicationInsightsProfiler3] 連結。 [連續 WebJob 詳細資料] 窗格隨即開啟。

      Screenshot that shows the Continuous WebJob Details pane.

如果 Profiler 仍然無法為您運作,請下載記錄並提交 Azure 支援票證

檢查診斷服務網站延伸模組的狀態頁面

如果 Profiler 是透過入口網站中的 [Application Insights] 窗格啟用,診斷服務網站延伸模組就會加以啟用。 您可以移至 https://{site-name}.scm.azurewebsites.net/DiagnosticServices 來檢查這個延伸模組的 [狀態頁面]。

注意

狀態頁面連結的網域會根據雲端而有所不同。 此網域會與 App Service 的 Kudu 管理網站相同。

此狀態頁面會顯示 Profiler 和快照偵錯工具代理程式的安裝狀態。 如果發生非預期的錯誤,它會出現並顯示如何修正錯誤的步驟。

您可以使用適用於 App Service 的 Kudu 管理網站來取得此 [狀態頁面] 的基底 URL:

  1. 在 Azure 入口網站中開啟您的 App Service 應用程式。
  2. 選取 [進階工具]
  3. 選取 [執行]
  4. 在 Kudu 管理網站上:
    1. 附加 /DiagnosticServices 至URL。
    2. 選取 [輸入]。

其結尾類似 https://<kudu-url>/DiagnosticServices

狀態頁面看起來類似下列範例。

Screenshot that shows the Diagnostic Services status page.

注意

Application Insights Profiler 的無程式碼安裝遵循 .NET Core 支援原則。 如需支援執行階段的詳細資訊,請參閱 .NET Core 支援原則

手動安裝

當您設定 Profiler 時,系統會對 Web 應用程式的設定進行更新。 如有必要,您可以手動套用更新

太多個使用中分析工作階段

您最多可以在於相同服務方案中執行的 4 個 Web 應用程式上啟用 Profiler。 如果您在 4 個以上的 Web 應用程式上執行,Profiler 可能會擲回下列錯誤:

Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException

若要解決這個問題,請將某些 Web 應用程式移至不同的服務方案。

部署錯誤:不是空目錄 'D:\home\site\wwwroot\App_Data\jobs'

如果您要將 Web 應用程式重新部署到已啟用 Profiler 的 Web Apps 資源,您可能會看到下列訊息:

「不是空目錄 'D:\home\site\wwwroot\App_Data\jobs」

如果您從指令碼或從 Azure Pipelines 執行 Web Deploy,就會發生此錯誤。 解決方法是將下列部署參數新增至 Web Deploy 工作:

-skip:Directory='.*\\App_Data\\jobs\\continuous\\ApplicationInsightsProfiler.*' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs\\continuous$' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs$'  -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data$'

這些參數會刪除 Application Insights Profiler 所使用的資料夾,並將重新部署程序解除封鎖。 它們並不會影響目前正在執行的 Profiler 執行個體。

Application Insights Profiler 是否正在執行?

Profiler 會在 Web 應用程式中以連續 WebJob 的形式執行。 您可以在 Azure 入口網站中開啟 Web 應用程式資源。 在 [WebJobs] 窗格中,檢查 ApplicationInsightsProfiler 的狀態。 如果它並沒有在執行,請開啟 [記錄] 以取得詳細資訊。

VM 和 Azure 雲端服務

若要查看 Azure 診斷是否已正確設定 Profiler:

  1. 確認所部署 Azure 診斷設定的內容是您所預期的內容。

  2. 確定 Azure 診斷在 Profiler 命令列上傳遞了正確的 iKey。

  3. 檢查 Profiler 記錄檔,以確認 Profiler 是否已執行但傳回錯誤。

若要檢查用來設定 Azure 診斷的設定:

  1. 登入虛擬機器 (VM)。

  2. 開啟此位置的記錄檔。 您電腦上的外掛程式版本可能較新。

    對於 VM:

    c:\WindowsAzure\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log
    

    針對 Azure 雲端服務:

    c:\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log
    
  3. 在該檔案中,搜尋 WadCfg 字串,以找出傳至 VM 用以設定 Azure 診斷的設定。

  4. 檢查以確認 Profiler 接收所使用的 iKey 是否正確。

  5. 檢查用來啟動 Profiler 的命令列。 用來啟動 Profiler 的引數位於下列檔案中 (磁碟機可以是 c:d:,而且目錄可能隱藏):

    對於 VM:

    C:\ProgramData\ApplicationInsightsProfiler\config.json
    

    針對 Azure 雲端服務:

    D:\ProgramData\ApplicationInsightsProfiler\config.json
    
  6. 確定 Profiler 命令列上的 iKey 正確無誤。

  7. 透過使用在上述 config.json 檔案中找到的路徑,檢查稱為 BootstrapN.log 的 Profiler 記錄檔。 其中顯示:

    • 偵錯資訊,指出 Profiler 所使用的設定。
    • 來自 Profiler 的狀態和錯誤訊息。

    您可以在這裡找到不同項目的檔案:

    對於 VM:

    C:\WindowsAzure\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    

    針對 Azure 雲端服務:

    C:\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    
  8. 如果在應用程式接收要求時,Profiler 正在執行中,則會顯示下列訊息:「從 iKey 中偵測到活動。」

  9. 在追蹤上傳期間,會顯示下列訊息:「開始上傳追蹤。」

編輯網路 Proxy 或防火牆規則

如果應用程式透過 Proxy 或防火牆連線至網際網路,您可能需要更新規則以與 Profiler 進行通訊。

Application Insights Profiler 所使用的 IP 包含在 Azure 監視器服務標籤中。 如需詳細資訊,請參閱服務標籤文件

支援

如果您仍然需要協助,請在 Azure 入口網站中提交支援票證。 記得納入錯誤訊息內的相互關聯識別碼。