針對 Azure 應用程式 Insights 代理程式 (先前稱為狀態監視器 v2) 進行疑難解答
本文提供疑難解答資訊,以協助解決啟用ApplicationInsights監視時可能會遇到的數據收集問題。
已知問題
應用程式 bin 目錄中的 DLL 衝突
如果任何動態連結庫 (DLL) 存在於 bin 目錄中,監視可能會失敗:
- Microsoft.ApplicationInsights.dll
- Microsoft.AspNet.TelemetryCorrelation.dll
- System.Diagnostics.DiagnosticSource.dll
這些 DLL 中有些會包含在 Visual Studio 預設應用程式範本中,即使您的應用程式未使用它們也一樣。 您可以使用疑難解答工具,例如下列工具,來查看徵兆行為:
PerfView:
ThreadID="7,500" ProcessorNumber="0" msg="Found 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' assembly, skipping attaching redfield binaries" ExtVer="2.8.13.5972" SubscriptionId="" AppName="" FormattedMessage="Found 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' assembly, skipping attaching redfield binaries"
IISReset 和應用程式載入 (,而不需要遙測) 。 使用 Sysinternals (Handle.exe 和 ListDLLs.exe) 進行調查:
.\handle64.exe -p w3wp | findstr /I "InstrumentationEngine AI. ApplicationInsights" E54: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll .\Listdlls64.exe w3wp | findstr /I "InstrumentationEngine AI ApplicationInsights" 0x0000000009be0000 0x127000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\MicrosoftInstrumentationEngine_x64.dll 0x0000000009b90000 0x4f000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll 0x0000000004d20000 0xb2000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.ApplicationInsights.Extensions.Base_x64.dll
PowerShell 版本
此產品是使用PowerShell 5.1版所撰寫和測試。 此模組與 PowerShell 第 6 或 7 版不相容。 建議您搭配使用 PowerShell 5.1 與較新的版本。 如需詳細資訊,請 參閱搭配 PowerShell 5.1 並行使用 PowerShell 7。
與 IIS 共用設定發生衝突
如果您有網頁伺服器的叢集,您可能會使用 共用組態。 HttpModule 無法插入此共享設定中。 在每部 Web 伺服器上執行 [啟用] 命令,將 DLL 安裝到每部伺服器的全域程式集緩存 (GAC) 。
執行 Enable 命令之後,請完成下列步驟:
移至共用組態目錄,並尋找 applicationHost.config 檔案。
將此 XML 程式代碼新增至 <組態的 modules> 區段:
<modules> <!-- Registered global managed http module handler. The 'Microsoft.AppInsights.IIS. ManagedHttpModuleHelper.dll' must be installed in the GAC before this config is applied. --> <add name="ManagedHttpModuleHelper" type="Microsoft.AppInsights.IIS.ManagedHttpModuleHelper. ManagedHttpModuleHelper, Microsoft.AppInsights.IIS.ManagedHttpModuleHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" /> </modules>
IIS 巢狀應用程式
我們不會在 1.0 版的 Internet Information Services (IIS) 中檢測巢狀應用程式。
無法使用進階 SDK 設定
SDK 組態不會在 1.0 版中公開給終端使用者。
針對 PowerShell 進行疑難解答
判斷可用的模組
您可以使用 Get-Module -ListAvailable
命令來判斷已安裝哪些模組。
將模組匯入目前的會話
如果模組尚未載入 PowerShell 工作階段中,您可以執行 命令來手動載入它 Import-Module <path to psd1>
。
針對 Application Insights 代理程式模組進行疑難解答
列出 Application Insights 代理程式模組中可用的命令
Get-Command -Module Az.ApplicationMonitor
執行 命令以取得可用的指令:
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Disable-ApplicationInsightsMonitoring 0.4.0 Az.ApplicationMonitor
Cmdlet Disable-InstrumentationEngine 0.4.0 Az.ApplicationMonitor
Cmdlet Enable-ApplicationInsightsMonitoring 0.4.0 Az.ApplicationMonitor
Cmdlet Enable-InstrumentationEngine 0.4.0 Az.ApplicationMonitor
Cmdlet Get-ApplicationInsightsMonitoringConfig 0.4.0 Az.ApplicationMonitor
Cmdlet Get-ApplicationInsightsMonitoringStatus 0.4.0 Az.ApplicationMonitor
Cmdlet Set-ApplicationInsightsMonitoringConfig 0.4.0 Az.ApplicationMonitor
Cmdlet Start-ApplicationInsightsMonitoringTrace 0.4.0 Az.ApplicationMonitor
判斷 Application Insights 代理程式模組的目前版本
Get-ApplicationInsightsMonitoringStatus -PowerShellModule
執行 命令以顯示模組的下列相關信息:
- PowerShell 模組版本
- Application Insights SDK 版本
- PowerShell 模組的檔案路徑
如需如何使用此 Cmdlet 的詳細描述,請檢閱 Get-ApplicationInsightsMonitoringStatus 參考 。
針對執行中的進程進行疑難解答
您可以檢查已檢測電腦上的進程,以判斷是否已載入所有 DLL 並設定環境變數。 如果監視正常運作,至少應載入 12 個 DLL。
Get-ApplicationInsightsMonitoringStatus -InspectProcess
使用 命令來檢查 DLL。(Get-Process -id <process-identifier>).StartInfo.EnvironmentVariables
使用 命令來檢查環境變數。 下列環境變數是在背景工作進程或 .NET Core 進程中設定:
COR_ENABLE_PROFILING=1
COR_PROFILER={324F817A-7420-4E6D-B3C1-143FBED6D855}
COR_PROFILER_PATH_32=<path-to-MicrosoftInstrumentationEngine_x86.dll>
COR_PROFILER_PATH_64=<path-to-MicrosoftInstrumentationEngine_x64.dll>
MicrosoftInstrumentationEngine_Host={CA487940-57D2-10BF-11B2-A3AD5A13CBC0}
MicrosoftInstrumentationEngine_HostPath_32=<path-to-Microsoft.ApplicationInsights.ExtensionsHost_x86.dll>
MicrosoftInstrumentationEngine_HostPath_64=<path-to-Microsoft.ApplicationInsights.ExtensionsHost_x64.dll>
MicrosoftInstrumentationEngine_ConfigPath32_Private=<path-to-Microsoft.InstrumentationEngine.Extensions.config>
MicrosoftInstrumentationEngine_ConfigPath64_Private=<path-to-Microsoft.InstrumentationEngine.Extensions.config>
MicrosoftAppInsights_ManagedHttpModulePath=<path-to-Microsoft.ApplicationInsights.RedfieldIISModule.dll>
MicrosoftAppInsights_ManagedHttpModuleType=Microsoft.ApplicationInsights.RedfieldIISModule.RedfieldIISModule
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.StartupBootstrapper
DOTNET_STARTUP_HOOKS=<path-to-Microsoft.ApplicationInsights.StartupHook.dll>
如需如何使用此 Cmdlet 的詳細描述,請檢閱 Get-ApplicationInsightsMonitoringStatus 參考 。
使用 PerfView 收集 ETW 記錄
安裝程式
從 GitHub 下載 PerfView.exe。
執行 PerfView.exe。
在功能表欄上,選取 [ 收集>]。
展開 [ 進階選項]。
清除下列複選框:
- Zip
- Merge
- .NET 符號集合
設定下列 其他提供者:
*Microsoft-ApplicationInsights-AspNetCore,*Microsoft-ApplicationInsights-AspNetCore-AiHostingStartup,*Microsoft-ApplicationInsights-AspNetCore-StartupBootstrapper,*Microsoft-ApplicationInsights-AspNetCore-StartupHook,*Microsoft-ApplicationInsights-Core,*Microsoft-ApplicationInsights-Data,*Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Dependency,*Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Web,*Microsoft-ApplicationInsights-Extensibility-DependencyCollector,*Microsoft-ApplicationInsights-Extensibility-EventCounterCollector,*Microsoft-ApplicationInsights-Extensibility-EventSourceListener,*Microsoft-ApplicationInsights-Extensibility-HostingStartup,*Microsoft-ApplicationInsights-Extensibility-PerformanceCollector,*Microsoft-ApplicationInsights-Extensibility-PerformanceCollector-QuickPulse,*Microsoft-ApplicationInsights-Extensibility-Web,*Microsoft-ApplicationInsights-Extensibility-WindowsServer,*Microsoft-ApplicationInsights-FrameworkLightup,*Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper,*Microsoft-ApplicationInsights-Java-IPA,*Microsoft-ApplicationInsights-LoggerProvider,*Microsoft-ApplicationInsights-Nodejs-IPA,*Microsoft-ApplicationInsights-RedfieldIISModule,*Microsoft-ApplicationInsights-SnapshotCollectorLightup,*Microsoft-ApplicationInsights-WindowsServer-Core,*Microsoft-ApplicationInsights-WindowsServer-TelemetryChannel,*Redfield-Microsoft-ApplicationInsights-AspNetCore,*Redfield-Microsoft-ApplicationInsights-Core,*Redfield-Microsoft-ApplicationInsights-Data,*Redfield-Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Dependency,*Redfield-Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Web,*Redfield-Microsoft-ApplicationInsights-Extensibility-DependencyCollector,*Redfield-Microsoft-ApplicationInsights-Extensibility-EventCounterCollector,*Redfield-Microsoft-ApplicationInsights-Extensibility-EventSourceListener,*Redfield-Microsoft-ApplicationInsights-Extensibility-PerformanceCollector,*Redfield-Microsoft-ApplicationInsights-Extensibility-PerformanceCollector-QuickPulse,*Redfield-Microsoft-ApplicationInsights-Extensibility-Web,*Redfield-Microsoft-ApplicationInsights-Extensibility-WindowsServer,*Redfield-Microsoft-ApplicationInsights-LoggerProvider,*Redfield-Microsoft-ApplicationInsights-WindowsServer-TelemetryChannel
收集記錄
在具有系統管理員許可權的命令控制台中
iisreset /stop
,執行 命令以關閉 IIS 和所有 Web 應用程式。在 PerfView 中,選取 [開始收集]。
在具有系統管理員許可權的命令控制台中
iisreset /start
,執行 命令以啟動 IIS。嘗試瀏覽至您的應用程式。
載入您的應用程式之後,返回 PerfView,然後選取 [ 停止收集]。
後續步驟
- 檢閱 API 參考 以瞭解您可能遺漏的參數。
與我們連絡,以取得說明
如果您有問題或需要相關協助,請建立支援要求,或詢問 Azure community 支援。 您也可以將產品意見反應提交給 Azure 意應見反社群。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應