排查 Azure 应用程序 Insights 代理 (以前状态监视器 v2)
本文提供故障排除信息,以帮助解决启用 Application Insights 监视时可能会遇到的数据收集问题。
已知问题
应用的 bin 目录中有冲突的 DLL
如果 bin 目录中存在这些动态链接库中的任何 (DLL) ,则监视可能会失败:
- 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 7 与 PowerShell 5.1 并排使用。
与 IIS 共享配置冲突
如果你有一个 Web 服务器群集,则可能正在使用 共享配置。 无法将 HttpModule 注入到此共享配置中。 在每个 Web 服务器上运行 Enable 命令,将 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 嵌套应用程序
我们不检测 Internet Information Services (IIS) 1.0 版中的嵌套应用程序。
高级 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 社区支持。 还可以向 Azure 反馈社区提交产品反馈。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈