为本地服务器部署 Azure Monitor Application Insights 代理
- 项目
Application Insights 代理(以前称为状态监视器 V2)是发布到 PowerShell 库的 PowerShell 模块。 它将替换状态监视器。 遥测数据将发送到 Azure 门户,你可以在其中监视应用。
有关支持的自动检测方案的完整列表,请参阅支持的环境、语言和资源提供程序。
备注
本模块当前支持通过 IIS 托管的 ASP.NET 和 ASP.NET Core web 应用的无代码检测。 使用 SDK 检测 Java 和 Node.js 应用程序。
Application Insights 代理位于 PowerShell 库中。
- 若要开始使用简洁的代码示例,请参阅“入门”选项卡。
- 若要深入了解如何开始使用,请参阅“详细说明”选项卡。
- 有关 PowerShell API 参考,请参阅“API 参考”选项卡。
- 有关发行说明更新,请参阅“发行说明”选项卡。
此选项卡包含应适用于大多数环境的快速入门命令。 这些说明依赖于 PowerShell 库来分发更新。 这些命令支持 PowerShell -Proxy
参数。
有关这些命令的说明、自定义说明以及有关故障排除的信息,请参阅详细说明。
如果没有 Azure 订阅,可在开始前创建一个试用帐户。
使用 PowerShell 库来下载并安装。
若要启用监视,你必须有一个连接字符串。 连接字符串将显示在 Application Insights 资源的“概述”窗格上。 有关详细信息,请参阅连接字符串。
以管理员身份运行 PowerShell。
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name PowerShellGet -Force
关闭 PowerShell。
以管理员身份运行 PowerShell。
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Install-Module -Name Az.ApplicationMonitor -AllowPrerelease -AcceptLicense
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Enable-ApplicationInsightsMonitoring -ConnectionString 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.cn/'
还可以手动下载并安装。
从 PowerShell 库手动下载最新版本的模块。
$pathToNupkg = "C:\Users\t\Desktop\Az.ApplicationMonitor.0.3.0-alpha.nupkg"
$pathToZip = ([io.path]::ChangeExtension($pathToNupkg, "zip"))
$pathToNupkg | rename-item -newname $pathToZip
$pathInstalledModule = "$Env:ProgramFiles\WindowsPowerShell\Modules\Az.ApplicationMonitor"
Expand-Archive -LiteralPath $pathToZip -DestinationPath $pathInstalledModule
Enable-ApplicationInsightsMonitoring -ConnectionString 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.cn/'
此选项卡介绍如何载入到 PowerShell 库和下载 ApplicationMonitor 模块。 包含了开始使用所需的最常见参数。 我们还提供手动下载说明,以防你无法访问 Internet。
若要开始,需要连接字符串。 有关详细信息,请参阅连接字符串。
PowerShell 需要拥有管理员级别的权限才能对计算机进行更改。
- 说明:默认禁用 PowerShell 脚本的运行。 我们建议仅允许在当前范围运行 RemoteSigned 脚本。
- 参考:关于执行策略和 Set-ExecutionPolicy。
- 命令:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
。 - 可选参数:
-Force
。 跳过确认提示。
示例错误
Install-Module : The 'Install-Module' command was found in the module 'PowerShellGet', but the module could not be
loaded. For more information, run 'Import-Module PowerShellGet'.
Import-Module : File C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.3.1\PackageManagement.psm1 cannot
be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
运行 $PSVersionTable
命令,审核 PowerShell 的实例。
该命令生成以下输出:
Name Value
---- -----
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
这些说明是在运行 Windows 10 和以下版本的计算机上编写和测试的。
这些步骤准备服务器以从 PowerShell 库下载模块。
备注
Windows 10、Windows Server 2016 和 PowerShell 6+ 支持 PowerShell 库。 有关早期版本的信息,请参阅安装 PowerShellGet。
以管理员身份使用提升的执行策略运行 PowerShell。
安装 NuGet 包提供程序。
- 说明:需要使用此提供程序才能与基于 NuGet 的存储库(例如 PowerShell 库)交互。
- 参考:Install-PackageProvider。
- 命令:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201
。 - 可选参数:
-Proxy
。 指定请求的代理服务器。-Force
。 跳过确认提示。
如果未设置 NuGet,则会看到此提示:
NuGet provider is required to continue PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users\t\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
将 PowerShell 库配置为受信任的存储库。
- 说明:默认情况下,PowerShell 库是不受信任的存储库。
- 参考:Set-PSRepository。
- 命令:
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
。 - 可选参数:
-Proxy
。 指定请求的代理服务器。
如果 PowerShell 库不受信任,则会看到此提示:
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
可以通过运行
Get-PSRepository
命令来确认此更改并审核所有PSRepositories
。安装最新版本的 PowerShellGet。
- 说明:此模块包含用于从 PowerShell 库中获取其他模块的工具。 Windows 10 和 Windows Server 随附了版本 1.0.0.1。 需要 1.6.0 或更高版本。 若要确定安装了哪个版本,请运行
Get-Command -Module PowerShellGet
命令。 - 参考:安装 PowerShellGet。
- 命令:
Install-Module -Name PowerShellGet
。 - 可选参数:
-Proxy
。 指定请求的代理服务器。-Force
。 忽略“已安装”警告并安装最新版本。
如果使用的不是最新 PowerShellGet 版本,则会看到此错误:
Install-Module : A parameter cannot be found that matches parameter name 'AllowPrerelease'. At line:1 char:20 Install-Module abc -AllowPrerelease ~~~~~~~~~~~~~~~~ CategoryInfo : InvalidArgument: (:) [Install-Module], ParameterBindingException FullyQualifiedErrorId : NamedParameterNotFound,Install-Module
- 说明:此模块包含用于从 PowerShell 库中获取其他模块的工具。 Windows 10 和 Windows Server 随附了版本 1.0.0.1。 需要 1.6.0 或更高版本。 若要确定安装了哪个版本,请运行
重启 PowerShell。 无法在当前会话中加载新版本。 新 PowerShell 会话会加载最新版 PowerShellGet。
这些步骤将从 PowerShell 库下载 Az.ApplicationMonitor 模块。
- 确保满足 PowerShell 库的所有先决条件。
- 以管理员身份使用提升的执行策略运行 PowerShell。
- 安装 Az.ApplicationMonitor 模块。
- 参考:Install-Module。
- 命令:
Install-Module -Name Az.ApplicationMonitor
。 - 可选参数:
-Proxy
。 指定请求的代理服务器。-AllowPrerelease
。 允许安装 alpha 和 beta 版本。-AcceptLicense
。 跳过“接受许可证”提示-Force
。 忽略“不受信任的存储库”警告。
如果出于任何原因无法连接到 PowerShell 模块,可以手动下载并安装 Az.ApplicationMonitor 模块。
- 转到 https://www.powershellgallery.com/packages/Az.ApplicationMonitor 。
- 在“版本历史记录”表中选择文件的最新版本。
- 在“安装选项”下选择“手动下载”。
将手动下载的 PowerShell 模块安装到 PowerShell 目录中,使之可被 PowerShell 会话发现。 有关详细信息,请参阅安装 PowerShell 模块。
说明:基础版本的 Microsoft.PowerShell.Archive (v1.0.1.0) 无法解压缩 nupkg 文件。 使用 .zip 扩展名重命名文件。
参考:Expand-Archive。
命令:
$pathToNupkg = "C:\az.applicationmonitor.0.3.0-alpha.nupkg" $pathToZip = ([io.path]::ChangeExtension($pathToNupkg, "zip")) $pathToNupkg | rename-item -newname $pathToZip $pathInstalledModule = "$Env:ProgramFiles\WindowsPowerShell\Modules\az.applicationmonitor" Expand-Archive -LiteralPath $pathToZip -DestinationPath $pathInstalledModule
说明:使用最新版本的 Expand-Archive 解压缩 nupkg 文件但不更改扩展名。
命令:
$pathToNupkg = "C:\az.applicationmonitor.0.2.1-alpha.nupkg" $pathInstalledModule = "$Env:ProgramFiles\WindowsPowerShell\Modules\az.applicationmonitor" Expand-Archive -LiteralPath $pathToNupkg -DestinationPath $pathInstalledModule
将手动下载的 PowerShell 模块安装到 PowerShell 目录中,使之可被 PowerShell 会话发现。 有关详细信息,请参阅安装 PowerShell 模块。
若要将模块安装到任何其他目录中,请使用 Import-Module 手动导入模块。
重要
DLL 会通过相对路径进行安装。 请将此包的内容存储到所需的运行时目录中,并确认访问权限允许读取但不允许写入。
- 将扩展名更改为“.zip”,并将包的内容解压缩到所需的安装目录中。
- 找到 Az.ApplicationMonitor.psd1 的文件路径。
- 以管理员身份使用提升的执行策略运行 PowerShell。
- 通过
Import-Module Az.ApplicationMonitor.psd1
命令加载模块。
监视专用 Intranet 中的计算机时,需要通过代理路由 HTTP 流量。
用于从 PowerShell 库下载并安装 Az.ApplicationMonitor 的 PowerShell 命令支持 -Proxy
参数。
编写安装脚本时,请查看上述说明。
Application Insights SDK 需要将应用的遥测数据发送给 Microsoft。 建议在 web.config 文件中配置应用的代理设置。 有关详细信息,请参阅如何实现实现代理直通?。
使用 Enable-ApplicationInsightsMonitoring
命令以启用监视。
有关如何使用此 cmdlet 的详细说明,请参阅 API 参考。
此选项卡介绍以下 cmdlet,它们是 Az.ApplicationMonitor PowerShell 模块的成员:
- Enable-InstrumentationEngine
- Enable-ApplicationInsightsMonitoring
- Disable-InstrumentationEngine
- Disable-ApplicationInsightsMonitoring
- Get-ApplicationInsightsMonitoringConfig
- Get-ApplicationInsightsMonitoringStatus
- Set-ApplicationInsightsMonitoringConfig
- Start-ApplicationInsightsMonitoringTrace
备注
- 若要开始,需要连接字符串。 有关详细信息,请参阅创建资源。
- 此 cmdlet 要求查看并接受我们的许可条款和隐私声明。
重要
此 cmdlet 要求使用管理员权限和提升的执行策略建立 PowerShell 会话。 有关详细信息,请参阅以管理员身份使用提升的执行策略运行 PowerShell。
- 此 cmdlet 要求查看并接受我们的许可条款和隐私声明。
- 检测引擎会增加额外的开销,默认情况下处于关闭状态。
通过设置一些注册表项启用检测引擎。 重启 IIS 以使这些更改生效。
检测引擎可以补充 .NET SDK 收集的数据。 它收集描述托管进程执行的事件和消息。 这些事件和消息包括依赖项结果代码、HTTP 谓词和 SQL 命令文本。
在以下情况下启用检测引擎:
- 已使用
Enable
cmdlet 启用了监视,但未启用检测引擎。 - 已使用 .NET SDK 手动检测应用,并希望收集额外的遥测数据。
Enable-InstrumentationEngine
可选。 使用此开关可在无外设安装中接受许可条款和隐私声明。
通用参数。 使用此开关可输出详细日志。
Configuring IIS Environment for instrumentation engine...
Configuring registry for instrumentation engine...
对目标计算机上的 IIS 应用启用无代码附加监视。
此 cmdlet 会修改 IIS applicationHost.config 并设置一些注册表项。 它会创建 applicationinsights.ikey.config 文件,该文件定义每个应用使用的检测密钥。 IIS 在启动时会加载 RedfieldModule,从而在应用程序启动时将 Application Insights SDK 注入到应用程序中。 重启 IIS 以使更改生效。
启用监视后,我们建议你使用实时指标快速检查应用是否正在向我们发送遥测数据。
在此示例中,当前计算机上的所有应用都分配了一个连接字符串。
Enable-ApplicationInsightsMonitoring -ConnectionString 'InstrumentationKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;IngestionEndpoint=https://xxxx.applicationinsights.azure.cn/'
在此示例中,将为当前计算机上的所有应用分配一个检测密钥。
Enable-ApplicationInsightsMonitoring -InstrumentationKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
在本示例中:
MachineFilter
使用'.*'
通配符匹配当前计算机。AppFilter='WebAppExclude'
提供null
检测密钥。 未检测指定的应用。AppFilter='WebAppOne'
为指定的应用分配唯一的检测密钥。AppFilter='WebAppTwo'
为指定的应用分配唯一的检测密钥。AppFilter
使用'.*'
通配符来匹配它尚未匹配的任何 Web 应用,并分配默认检测密钥。- 添加空格以提高可读性。
Enable-ApplicationInsightsMonitoring -InstrumentationKeyMap `
` @(@{MachineFilter='.*';AppFilter='WebAppExclude'},
` @{MachineFilter='.*';AppFilter='WebAppOne';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1'}},
` @{MachineFilter='.*';AppFilter='WebAppTwo';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx2'}},
` @{MachineFilter='.*';AppFilter='.*';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxdefault'}})
备注
在此上下文中,AppFilter 的命名可能会造成混淆,AppFilter
可设置应用程序名称 regex 筛选器(如果 IIS 上是 .NET,则为 HostingEnvironment.SiteName)。 VirtualPathFilter
会设置虚拟路径 regex 筛选器(如果 IIS 上是 .NET,则为 HostingEnvironment.ApplicationVirtualPath)。 若要检测单个应用,可以使用如下 VirtualPathFilter:Enable-ApplicationInsightsMonitoring -InstrumentationKeyMap @(@{VirtualPathFilter="^/MyAppName$"; InstrumentationSettings=@{InstrumentationKey='<your ikey>'}})
必需。 使用此参数提供单个连接字符串以供目标计算机上的所有应用使用。
必需。 使用此参数提供单个检测密钥以供目标计算机上的所有应用使用。
必需。 使用此参数可提供多个检测密钥以及每个应用使用的检测密钥映射。
通过设置 MachineFilter
,可以为多台计算机创建单个安装脚本。
重要
应用按照提供规则的顺序与规则相匹配。 因此,你应该首先指定最特定的规则,最后指定最通用的规则。
@(@{MachineFilter='.*';AppFilter='.*';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}})
- MachineFilter 是计算机或 VM 名称所需的 C# 正则表达式。
- “.*”匹配所有项
- “ComputerName”仅匹配具有指定确切名称的计算机。
- AppFilter 是 IIS 站点名称所需的 C# 正则表达式。 可以通过运行命令 get-iissite 获取服务器上的站点列表。
- “.*”匹配所有项
- “SiteName”仅匹配具有指定确切名称的 IIS 站点。
- 需要 InstrumentationKey 才能监视与上述两个筛选器匹配的应用。
- 如果要定义排除监视的规则,请将此值保留为 null。
可选。 使用此开关可让检测引擎收集执行托管进程期间发生的事件和相关消息。 这些事件和消息包括依赖项结果代码、HTTP 谓词和 SQL 命令文本。
检测引擎会增加开销,默认情况下处于关闭状态。
可选。 使用此开关可在无外设安装中接受许可条款和隐私声明。
当你使用一组 Web 服务器时,你可能正在使用共享配置。 HttpModule 无法注入此共享配置。 此脚本将失败,并提示需要额外的安装步骤。 使用此开关可忽略该检查并继续安装必备组件。 有关详细信息,请参阅已知与 iis 共享配置的冲突
通用参数。 使用此开关可显示详细日志。
通用参数。 使用此开关可以测试和验证输入参数,而无需真正启用监视。
Initiating Disable Process
Applying transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config'
'C:\Windows\System32\inetsrv\config\applicationHost.config' backed up to 'C:\Windows\System32\inetsrv\config\applicationHost.config.backup-2019-03-26_08-59-52z'
in :1,237
No element in the source document matches '/configuration/location[@path='']/system.webServer/modules/add[@name='ManagedHttpModuleHelper']'
Not executing RemoveAll (transform line 1, 546)
Transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config' was successfully applied. Operation: 'disable'
GAC Module will not be removed, since this operation might cause IIS instabilities
Configuring IIS Environment for codeless attach...
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS[Environment]
Configuring IIS Environment for instrumentation engine...
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS[Environment]
Configuring registry for instrumentation engine...
Successfully disabled Application Insights Agent
Installing GAC module 'C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\0.2.0\content\Runtime\Microsoft.AppInsights.IIS.ManagedHttpModuleHelper.dll'
Applying transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config'
Found GAC module Microsoft.AppInsights.IIS.ManagedHttpModuleHelper.ManagedHttpModuleHelper, Microsoft.AppInsights.IIS.ManagedHttpModuleHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
'C:\Windows\System32\inetsrv\config\applicationHost.config' backed up to 'C:\Windows\System32\inetsrv\config\applicationHost.config.backup-2019-03-26_08-59-52z_1'
Transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config' was successfully applied. Operation: 'enable'
Configuring IIS Environment for codeless attach...
Configuring IIS Environment for instrumentation engine...
Configuring registry for instrumentation engine...
Updating app pool permissions...
Successfully enabled Application Insights Agent
通过删除一些注册表项来禁用检测引擎。 重启 IIS 以使这些更改生效。
Disable-InstrumentationEngine
通用参数。 使用此开关可输出详细日志。
Configuring IIS Environment for instrumentation engine...
Registry: removing 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN[Environment]'
Registry: removing 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC[Environment]'
Registry: removing 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS[Environment]'
Configuring registry for instrumentation engine...
在目标计算机上禁用监视。 此 cmdlet 会删除对 IIS applicationHost.config 的编辑并删除注册表项。
Disable-ApplicationInsightsMonitoring
通用参数。 使用此开关可显示详细日志。
Initiating Disable Process
Applying transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config'
'C:\Windows\System32\inetsrv\config\applicationHost.config' backed up to 'C:\Windows\System32\inetsrv\config\applicationHost.config.backup-2019-03-26_08-59-00z'
in :1,237
No element in the source document matches '/configuration/location[@path='']/system.webServer/modules/add[@name='ManagedHttpModuleHelper']'
Not executing RemoveAll (transform line 1, 546)
Transformation to 'C:\Windows\System32\inetsrv\config\applicationHost.config' was successfully applied. Operation: 'disable'
GAC Module will not be removed, since this operation might cause IIS instabilities
Configuring IIS Environment for codeless attach...
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS[Environment]
Configuring IIS Environment for instrumentation engine...
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC[Environment]
Registry: skipping non-existent 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS[Environment]
Configuring registry for instrumentation engine...
Successfully disabled Application Insights Agent
获取配置文件并将值输出到控制台。
Get-ApplicationInsightsMonitoringConfig
不需要参数。
RedfieldConfiguration:
Filters:
0)InstrumentationKey: AppFilter: WebAppExclude MachineFilter: .*
1)InstrumentationKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx2 AppFilter: WebAppTwo MachineFilter: .*
2)InstrumentationKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxdefault AppFilter: .* MachineFilter: .*
此 cmdlet 提供有关 Application Insights 代理的故障排除信息。 使用此 cmdlet 调查监视状态、PowerShell 模块的版本,以及检查正在运行的进程。 此 cmdlet 会报告监视所需的版本信息和密钥文件相关信息。
运行 Get-ApplicationInsightsMonitoringStatus
命令来显示网站的监视状态。
Get-ApplicationInsightsMonitoringStatus
IIS Websites:
SiteName : Default Web Site
ApplicationPoolName : DefaultAppPool
SiteId : 1
SiteState : Stopped
SiteName : DemoWebApp111
ApplicationPoolName : DemoWebApp111
SiteId : 2
SiteState : Started
ProcessId : not found
SiteName : DemoWebApp222
ApplicationPoolName : DemoWebApp222
SiteId : 3
SiteState : Started
ProcessId : 2024
Instrumented : true
InstrumentationKey : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx123
SiteName : DemoWebApp333
ApplicationPoolName : DemoWebApp333
SiteId : 4
SiteState : Started
ProcessId : 5184
AppAlreadyInstrumented : true
在此示例中,
计算机标识符是一个匿名 ID,用于唯一标识服务器。 如果你创建支持请求,我们需要该 ID 来查找你的服务器的日志。
“默认网站”在 IIS 中处于“已停止”状态
DemoWebApp111 已在 IIS 中启动,但尚未收到任何请求。 此报告显示没有正在运行的进程(ProcessId:找不到)。
DemoWebApp222 正在运行且正受监视(已检测:是)。 根据用户配置,此站点的检测密钥 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx123 匹配。
DemoWebApp333 已使用 Application Insights SDK 进行手动检测。 Application Insights 代理检测到此 SDK,且不会监视此站点。
存在
AppAlreadyInstrumented : true
表示 Application Insights 代理标识了在 Web 应用程序中加载的冲突 dll,假定 Web 应用已手动检测,并且代理已退让且未检测此过程。Instrumented : true
指示 Application Insights 代理已成功检测在指定的 w3wp.exe 进程中运行的 Web 应用。
运行 Get-ApplicationInsightsMonitoringStatus -PowerShellModule
命令可显示有关当前模块的信息:
Get-ApplicationInsightsMonitoringStatus -PowerShellModule
PowerShell Module version:
0.4.0-alpha
Application Insights SDK version:
2.9.0.3872
Executing PowerShell Module Assembly:
Microsoft.ApplicationInsights.Redfield.Configurator.PowerShell, Version=2.8.14.11432, Culture=neutral, PublicKeyToken=31bf3856ad364e35
PowerShell Module Directory:
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\0.2.2\content\PowerShell
Runtime Paths:
ParentDirectory (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content
ConfigurationPath (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\applicationInsights.ikey.config
ManagedHttpModuleHelperPath (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AppInsights.IIS.ManagedHttpModuleHelper.dll
RedfieldIISModulePath (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll
InstrumentationEngine86Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation32\MicrosoftInstrumentationEngine_x86.dll
InstrumentationEngine64Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\MicrosoftInstrumentationEngine_x64.dll
InstrumentationEngineExtensionHost86Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation32\Microsoft.ApplicationInsights.ExtensionsHost_x86.dll
InstrumentationEngineExtensionHost64Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll
InstrumentationEngineExtensionConfig86Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation32\Microsoft.InstrumentationEngine.Extensions.config
InstrumentationEngineExtensionConfig64Path (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.InstrumentationEngine.Extensions.config
ApplicationInsightsSdkPath (Exists: True)
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.dll
可以检查已检测计算机上的进程以查看是否已加载所有 DLL。 如果监视正常工作,则至少应加载 12 个 DLL。
运行命令 Get-ApplicationInsightsMonitoringStatus -InspectProcess
:
Get-ApplicationInsightsMonitoringStatus -InspectProcess
iisreset.exe /status
Status for IIS Admin Service ( IISADMIN ) : Running
Status for Windows Process Activation Service ( WAS ) : Running
Status for Net.Msmq Listener Adapter ( NetMsmqActivator ) : Running
Status for Net.Pipe Listener Adapter ( NetPipeActivator ) : Running
Status for Net.Tcp Listener Adapter ( NetTcpActivator ) : Running
Status for World Wide Web Publishing Service ( W3SVC ) : Running
handle64.exe -accepteula -p w3wp
BF0: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.ServerTelemetryChannel.dll
C58: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.AzureAppServices.dll
C68: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.DependencyCollector.dll
C78: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.WindowsServer.dll
C98: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.Web.dll
CBC: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.PerfCounterCollector.dll
DB0: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.AI.Agent.Intercept.dll
B98: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll
BB4: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.Contracts.dll
BCC: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.Redfield.Lightup.dll
BE0: File (R-D) C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.dll
listdlls64.exe -accepteula w3wp
0x0000000019ac0000 0x127000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\MicrosoftInstrumentationEngine_x64.dll
0x00000000198b0000 0x4f000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll
0x000000000c460000 0xb2000 C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Instrumentation64\Microsoft.ApplicationInsights.Extensions.Base_x64.dll
0x000000000ad60000 0x108000 C:\Windows\TEMP\2.4.0.0.Microsoft.ApplicationInsights.Extensions.Intercept_x64.dll
默认情况下,此 cmdlet 会报告 Web 应用程序的监视状态。 使用此选项来查看是否已成功检测应用程序。 也可查看哪个检测密钥已与站点匹配。
可选。 使用此开关报告监视所需的 DLL 的版本号和路径。 如果需要标识任何 DLL 的版本(包括 Application Insights SDK),请使用此选项。
可选。 使用此开关报告 IIS 是否正在运行。 它会下载外部工具,以确定是否将必要的 DLL 加载到 IIS 运行时。
如果此过程因任何原因失败,你可以手动运行这些命令:
- iisreset.exe /status
- handle64.exe -p w3wp | findstr /I "InstrumentationEngine AI. ApplicationInsights"
- listdlls64.exe w3wp | findstr /I "InstrumentationEngine AI ApplicationInsights"
可选。 仅与 InspectProcess 一起使用。 使用此开关可跳过在下载更多工具之前出现的用户提示。
在不进行完全重新安装的情况下设置配置文件。 重启 IIS 以使更改生效。
重要
此 cmdlet 需要具有管理员权限的 PowerShell 会话。
在此示例中,将为当前计算机上的所有应用分配一个检测密钥。
Enable-ApplicationInsightsMonitoring -InstrumentationKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
在本示例中:
MachineFilter
使用'.*'
通配符匹配当前计算机。AppFilter='WebAppExclude'
提供null
检测密钥。 未检测指定的应用。AppFilter='WebAppOne'
为指定的应用分配唯一的检测密钥。AppFilter='WebAppTwo'
为指定的应用分配唯一的检测密钥。AppFilter
使用'.*'
通配符来匹配它尚未匹配的 Web 应用,并分配默认检测密钥。- 添加空格以提高可读性。
Enable-ApplicationInsightsMonitoring -InstrumentationKeyMap `
` @(@{MachineFilter='.*';AppFilter='WebAppExclude'},
` @{MachineFilter='.*';AppFilter='WebAppOne';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx1'}},
` @{MachineFilter='.*';AppFilter='WebAppTwo';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx2'}},
` @{MachineFilter='.*';AppFilter='.*';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxdefault'}})
必需。 使用此参数提供单个检测密钥以供目标计算机上的所有应用使用。
必需。 使用此参数可提供多个检测密钥以及每个应用使用的检测密钥映射。
通过设置 MachineFilter
,可以为多台计算机创建单个安装脚本。
重要
应用按照提供规则的顺序与规则相匹配。 因此,你应该首先指定最特定的规则,最后指定最通用的规则。
@(@{MachineFilter='.*';AppFilter='.*';InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'})
- MachineFilter 是计算机或 VM 名称所需的 C# 正则表达式。
- “.*”匹配所有项
- “ComputerName”仅匹配具有指定名称的计算机。
- AppFilter 是计算机或 VM 名称所需的 C# 正则表达式。
- “.*”匹配所有项
- “ApplicationName”仅匹配具有指定名称的 IIS 应用。
- 需要 InstrumentationKey 才能监视与上述两个筛选器匹配的应用。
- 如果要定义排除监视的规则,请将此值保留为 null。
通用参数。 使用此开关可显示详细日志。
默认情况下没有输出。
VERBOSE: Operation: InstallWithIkey
VERBOSE: InstrumentationKeyMap parsed:
Filters:
0)InstrumentationKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx AppFilter: .* MachineFilter: .*
VERBOSE: set config file
VERBOSE: Config File Path:
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\applicationInsights.ikey.config
VERBOSE: Operation: InstallWithIkeyMap
VERBOSE: InstrumentationKeyMap parsed:
Filters:
0)InstrumentationKey: AppFilter: WebAppExclude MachineFilter: .*
1)InstrumentationKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx2 AppFilter: WebAppTwo MachineFilter: .*
2)InstrumentationKey: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxdefault AppFilter: .* MachineFilter: .*
VERBOSE: set config file
VERBOSE: Config File Path:
C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\applicationInsights.ikey.config
从无代码附加运行时收集 ETW 事件。 此 cmdlet 是运行 PerfView 的替代方法。
收集事件,实时输出到控制台,并保存到 ETL 文件。 可以使用 PerfView 打开输出 ETL 文件,以便进一步调查。
此 cmdlet 将一直运行到它达到超时持续时间(默认值为 5 分钟)或被手动停止 (Ctrl + C
)。
通常,我们会要求你收集事件,以调查未检测应用程序的原因。
在 IIS 启动时以及在应用程序启动时,无代码附加运行时会发出 ETW 事件。
若要收集这些事件,请执行以下操作:
- 在具有管理员权限的 cmd 控制台中,执行
iisreset /stop
以停止 IIS 和所有 Web 应用。 - 执行此 cmdlet
- 在具有管理权限的 cmd 控制台中,执行
iisreset /start
以启动 IIS。 - 尝试浏览到你的应用。
- 在应用完成加载后,你可以手动停止它 (
Ctrl + C
) 或等待超时。
收集事件时,你有下面三个选择:
- 使用开关
-CollectSdkEvents
收集从 Application Insights SDK 发出的事件。 - 使用开关
-CollectRedfieldEvents
收集由 Application Insights 和 Redfield 运行时发出的事件。 在诊断 IIS 和应用程序启动时,这些日志非常有用。 - 使用这两个开关可收集这两种事件类型。
- 默认情况下,如果未指定任何开关,将收集这两种事件类型。
可选。 使用此参数可设置此脚本应收集事件的时长。 默认值为 5 分钟。
可选。 使用此开关可设置 ETL 文件的输出目录。 默认情况下,此文件会在 PowerShell 模块目录中创建。 完整路径在脚本执行期间显示。
可选。 使用此开关可收集 Application Insights SDK 事件。
可选。 使用此开关收集来自 Application Insights 和 Redfield 运行时的事件。
通用参数。 使用此开关可输出详细日志。
Start-ApplicationInsightsMonitoringTrace -CollectRedfieldEvents
Starting...
Log File: C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\logs\20190627_144217_ApplicationInsights_ETW_Trace.etl
Tracing enabled, waiting for events.
Tracing will timeout in 5 minutes. Press CTRL+C to cancel.
2:42:31 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Resolved variables to: MicrosoftAppInsights_ManagedHttpModulePath='C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll', MicrosoftAppInsights_ManagedHttpModuleType='Microsoft.ApplicationInsights.RedfieldIISModule.RedfieldIISModule'
2:42:31 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Resolved variables to: MicrosoftDiagnosticServices_ManagedHttpModulePath2='', MicrosoftDiagnosticServices_ManagedHttpModuleType2=''
2:42:31 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Environment variable 'MicrosoftDiagnosticServices_ManagedHttpModulePath2' or 'MicrosoftDiagnosticServices_ManagedHttpModuleType2' is null, skipping managed dll loading
2:42:31 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace MulticastHttpModule.constructor, success, 70 ms
2:42:31 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace Current assembly 'Microsoft.ApplicationInsights.RedfieldIISModule, Version=2.8.18.27202, Culture=neutral, PublicKeyToken=f23a46de0be5d6f3' location 'C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll'
2:42:31 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace Matched filter '.*'~'STATUSMONITORTE', '.*'~'DemoWithSql'
2:42:31 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace Lightup assembly calculated path: 'C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.Redfield.Lightup.dll'
2:42:31 PM EVENT: Microsoft-ApplicationInsights-FrameworkLightup Trace Loaded applicationInsights.config from assembly's resource Microsoft.ApplicationInsights.Redfield.Lightup, Version=2.8.18.27202, Culture=neutral, PublicKeyToken=f23a46de0be5d6f3/Microsoft.ApplicationInsights.Redfield.Lightup.ApplicationInsights-recommended.config
2:42:34 PM EVENT: Microsoft-ApplicationInsights-FrameworkLightup Trace Successfully attached ApplicationInsights SDK
2:42:34 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace RedfieldIISModule.LoadLightupAssemblyAndGetLightupHttpModuleClass, success, 2687 ms
2:42:34 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace RedfieldIISModule.CreateAndInitializeApplicationInsightsHttpModules(lightupHttpModuleClass), success
2:42:34 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace ManagedHttpModuleHelper, multicastHttpModule.Init() success, 3288 ms
2:42:35 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Resolved variables to: MicrosoftAppInsights_ManagedHttpModulePath='C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationMonitor\content\Runtime\Microsoft.ApplicationInsights.RedfieldIISModule.dll', MicrosoftAppInsights_ManagedHttpModuleType='Microsoft.ApplicationInsights.RedfieldIISModule.RedfieldIISModule'
2:42:35 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Resolved variables to: MicrosoftDiagnosticServices_ManagedHttpModulePath2='', MicrosoftDiagnosticServices_ManagedHttpModuleType2=''
2:42:35 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace Environment variable 'MicrosoftDiagnosticServices_ManagedHttpModulePath2' or 'MicrosoftDiagnosticServices_ManagedHttpModuleType2' is null, skipping managed dll loading
2:42:35 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace MulticastHttpModule.constructor, success, 0 ms
2:42:35 PM EVENT: Microsoft-ApplicationInsights-RedfieldIISModule Trace RedfieldIISModule.CreateAndInitializeApplicationInsightsHttpModules(lightupHttpModuleClass), success
2:42:35 PM EVENT: Microsoft-ApplicationInsights-IIS-ManagedHttpModuleHelper Trace ManagedHttpModuleHelper, multicastHttpModule.Init() success, 0 ms
Timeout Reached. Stopping...
此处列出了发行说明更新。
- 将 Application Insights .NET/.NET Core SDK 更新为
2.21.0-redfield
- 将 Application Insights .NET/.NET Core SDK 更新为
2.20.1-redfield
- 启用了 SQL 查询集合
将 Application Insights .NET/.NET Core SDK 更新为 2.18.1-redfield
添加了 ASP.NET Core 自动检测功能
本部分提供常见问题的解答。
是的。 可以通过多种方式下载 Application Insights 代理:
- 如果计算机可以访问 Internet,则可以使用
-Proxy
参数登录到 PowerShell 库。 - 还可以手动下载此模块,并将其安装到计算机上或直接使用它。
上述每个选项都在详细说明中进行了说明。
是的。 在 Application Insights Agent 2.0.0 及更高版本中,支持在 IIS 中托管的 ASP.NET Core 应用程序。
可以使用 Get-ApplicationInsightsMonitoringStatus cmdlet 来验证启用是否成功。
使用实时指标来快速确定应用是否正在发送遥测数据。
还可以使用 Log Analytics 列出当前正在发送遥测数据的所有云角色:
union * | summarize count() by cloud_RoleName, cloud_RoleInstance
若要实现代理直通,请配置计算机级代理或应用程序级代理。 请参阅 DefaultProxy。
示例 Web.config:
<system.net>
<defaultProxy>
<proxy proxyaddress="http://xx.xx.xx.xx:yyyy" bypassonlocal="true"/>
</defaultProxy>
</system.net>
请参阅专用疑难解答文章。
Application Insights SDK 和代理发送遥测,将其作为 REST 调用引入到引入终结点。 可以使用原始 REST 客户端通过 PowerShell 或使用 curl 命令,测试从 Web 服务器或应用程序主机计算机到引入服务终结点的连接。 请参阅排查 Azure Monitor Application Insights 中缺失应用程序遥测的问题。
查看遥测:
添加更多遥测:
- 可用性概述
- 添加 Web 客户端遥测,以查看网页代码中的异常并启用跟踪调用。
- 将 Application Insights SDK 添加到代码,以便插入跟踪和日志调用。
使用 Application Insights 代理执行更多操作:
- 对 Application Insights 代理进行故障排除。