Application Insights 代理程式是發佈到 PowerShell 資源庫 (英文) 的 PowerShell 模組。 能取代狀態監視器。 遙測資料會被傳送至 Azure 入口網站,您可以在該處監控您的應用程式。
如需支援自動檢測案例的完整清單,請參閱支援的環境、語言和資源提供者。
附註
此模組目前支援以 Internet Information Server (IIS) 裝載之 ASP.NET 和 ASP.NET Core Web 應用程式的無程式碼檢測。 使用 SDK 來檢測 Java 和 Node.js 應用程式。
附註
默認會針對 ASP.NET Core 應用程式啟用用戶端監視。 如果您要停用用戶端監視,請使用下列資訊在伺服器中定義環境變數:
-
名稱:
APPINSIGHTS_JAVASCRIPT_ENABLED -
值:
false
PowerShell 資源庫
Application Insights 代理程式位於 PowerShell 資源庫。
說明
- 若要開始使用精簡的程式碼範例,請參閱 [開始使用] 索引標籤。
- 如需深入了解如何開始使用,請參閱 [詳細指示] 索引標籤。
- 如需 PowerShell API 參考,請參閱 [API 參考] 索引標籤。
- 如需版本資訊更新,請參閱 [發行備註] 索引標籤。
此索引標籤包含應適用於大部分環境的快速入門命令。 這些指令仰賴 PowerShell Gallery 散發更新。 這些命令支援 PowerShell -Proxy 參數。
如需這些命令的說明、自訂指示以及疑難排解的相關資訊,請參閱詳細指示。
如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶。
從 PowerShell 藝廊下載與安裝
透過 PowerShell 資源庫進行下載和安裝。
安裝先決條件
若要啟用監視,您必須具備連接字串。 連接字串會顯示在 Application Insights 資源的 [概觀] 窗格中。 如需詳細資訊,請參閱連接字串。
附註
如需您可能需要的其他必要條件,請參閱 PowerShell 資源庫傳輸層安全性 (TLS) 支援 (英文)。
以管理員身分執行 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。
安裝 Application Insights 代理程式
以管理員身分執行 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.com/'
手動下載並安裝 (離線選項)
您也可以手動下載和安裝。
下載模組
手動從 PowerShell 資源庫下載最新版的模組。
解壓縮並安裝 Application Insights 代理程式
$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.com/'
此索引標籤描述如何上線至 PowerShell 資源庫並下載 ApplicationMonitor 模組。 包含的是您需要開始使用的最常見參數。 如果您無法存取因特網,我們也提供手動下載指示。
取得連接字串
若要開始使用,您需要連接字串。 如需詳細資訊,請參閱連接字串。
使用提高權限的執行原則,以管理員身分執行 PowerShell
以管理員身分執行
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.
PowerShell 的先決條件
執行 $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 資源庫的必要條件
這些步驟會準備您的伺服器,從 PowerShell 資源庫下載模組。
附註
PowerShell 資源庫在 Windows 10、Windows Server 2016 和 PowerShell 6+ 上受支援。 如需舊版的相關資訊,請參閱安裝 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 Gallery 是不受信任的資料庫。
- 參考: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"):您可以執行
PSRepositories命令,來確認此變更並稽核所有Get-PSRepository。安裝最新版的 PowerShellGet。
- 描述:此模組包含用來從 PowerShell 資源庫取得其他模組的工具。 1.0.0.1 版隨附於 Windows 10 和 Windows Server。 需要 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 資源庫取得其他模組的工具。 1.0.0.1 版隨附於 Windows 10 和 Windows Server。 需要 1.6.0 版或更高版本。 若要判斷安裝的版本,請執行
重新啟動 PowerShell。 您無法在目前的工作階段中載入新版本。 新的 PowerShell 工作階段將會載入最新版的 PowerShellGet。
透過 PowerShell Gallery 下載並安裝模組
這些步驟會從 PowerShell 資源庫下載 Az.ApplicationMonitor 模組。
- 確定符合 PowerShell 資源庫的所有必要條件。
- 使用提高權限的執行原則,以管理員身分執行 PowerShell。
- 安裝 Az.ApplicationMonitor 模組。
- 參考:Install-Module。
- 命令:
Install-Module -Name Az.ApplicationMonitor。 - 選擇性參數:
-
-Proxy。 為請求指定代理伺服器。 -
-AllowPrerelease。 允許安裝 Alpha 版本和 Beta 版本。 -
-AcceptLicense。 略過「接受授權」提示 -
-Force。 略過「不受信任的存放庫」警告。
-
手動下載並安裝模組 (離線選項)
如果基於任何原因而無法連線到 PowerShell 模組,您可以手動下載並安裝 Az.ApplicationMonitor 模組。
手動下載最新的 nupkg 檔案
- 移至 https://www.powershellgallery.com/packages/Az.ApplicationMonitor。
- 在 [版本歷程記錄] 資料表中選取最新版的檔案。
- 在 [安裝選項] 底下,選取 [手動下載]。
選項 1:安裝至 PowerShell 模組目錄
將手動下載的 PowerShell 模組安裝至 PowerShell 目錄,讓 PowerShell 工作階段可以對其進行探索。 如需詳細資訊,請參閱安裝 PowerShell 模組。
使用 Expand-Archive (v1.0.1.0) 將 nupkg 解壓縮為 zip 檔案
描述: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 (v1.1.0.0) 解壓縮 nupkg
描述:使用目前版本的 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
選項 2:手動解壓縮並匯入 nupkg
將手動下載的 PowerShell 模組安裝至 PowerShell 目錄,讓 PowerShell 工作階段可以對其進行探索。 如需詳細資訊,請參閱安裝 PowerShell 模組。
如果您要將模組安裝至任何其他目錄,請使用 Import-Module 手動匯入模組。
重要
動態連結程式庫 (DLL) 會透過相對路徑安裝。 將套件的內容儲存在預定的執行階段目錄中,並確認存取權限允許讀取但不允許寫入。
- 將副檔名變更為 ".zip",並將套件的內容解壓縮到您預定的安裝目錄中。
- 尋找 Az.ApplicationMonitor.psd1 的檔案路徑。
- 使用提高權限的執行原則,以管理員身分執行 PowerShell。
- 使用
Import-Module Az.ApplicationMonitor.psd1命令載入模組。
透過 Proxy 路由傳送流量
當您監視私人內部網路上的電腦時,您需要通過代理伺服器來傳輸 HTTP 流量。
從 PowerShell 資源庫下載並安裝 Az.ApplicationMonitor 的 PowerShell 命令支援 -Proxy 參數。
當您撰寫安裝指令碼時,請檢閱上述指示。
Application Insights SDK 必須將應用程式的遙測資料傳送至 Microsoft。 建議您在 web.config 檔案中設定應用程式的 Proxy 設定。 如需詳細資訊,請參閱如何實現代理穿透?。
啟用監視
使用 Enable-ApplicationInsightsMonitoring 命令來啟用監視。
如需如何使用此 Cmdlet 的詳細描述,請參閱 API 參考。
此索引標籤描述下列 Cmdlet,這些 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 會要求您檢閱並接受我們的授權和隱私權聲明。
- 檢測引擎會增加更多額外負荷,且預設為關閉。
Enable-InstrumentationEngine
藉由設定一些登錄機碼來啟用檢測引擎。 請重新啟動 IIS 讓變更生效。
檢測引擎可以補充 .NET 軟體開發套件 (SDK) 所收集的資料。 會收集描述受控程序執行的事件和訊息。 這些事件和訊息包括相依性結果碼、HTTP 動詞和 SQL 命令文字。
如果有下列情形,請啟用檢測引擎:
- 您已使用
EnableCmdlet 啟用監視,但未啟用檢測引擎。 - 您使用 .NET SDK 手動設置應用程式,並想要收集額外的遙測資料。
範例
Enable-InstrumentationEngine
參數
-接受授權條款
選擇性。 使用此開關可在無界面安裝中接受授權和隱私權聲明。
-Verbose
一般參數。 使用此參數來輸出詳細的記錄。
輸出
成功啟用檢測引擎的範例輸出
Configuring IIS Environment for instrumentation engine...
Configuring registry for instrumentation engine...
Enable-ApplicationInsightsMonitoring (啟用應用程式洞察監控)
啟用目標電腦上 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.com/'
單一檢測金鑰的範例
在此範例中,會為目前電腦上的所有應用程式提供單一檢測金鑰。
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 是電腦或虛擬機器 (VM) 名稱的必要 C# 規則運算式。
- '.*' 符合全部
- 'ComputerName' 只會比對具有指定確切名稱的電腦。
-
AppFilter 是 IIS 網站名稱所需的 C# regex。 您可以藉由執行 get-iissite 命令,取得伺服器上網站的清單。
- '.*' 符合全部
- 'SiteName' 只會比對具有指定確切名稱的 IIS 網站。
-
InstrumentationKey 是必要項目,才能對符合上述兩個篩選條件的應用程式啟用監視。
- 如果您想要定義規則以排除監視,請將此值保留為 Null。
-EnableInstrumentationEngine
選擇性。 使用此參數可讓檢測引擎收集有關受控程序執行期間所發生的事件和訊息。 這些事件和訊息包括相依性結果碼、HTTP 動詞和 SQL 命令文字。
儀表引擎會增加額外負荷,預設為關閉。
-接受授權條款
選擇性。 使用此開關可在無界面安裝中接受授權和隱私權聲明。
-忽略共用配置
當您有 Web 服務器的叢集時,可以使用共用組態。 HttpModule 無法插入此共用設定中。 此指令碼會失敗,並顯示需要額外安裝步驟的訊息。 使用此開關來忽略該檢查並繼續安裝必要條件。 如需詳細資訊,請參閱已知的 IIS 共用設定衝突
-Verbose
一般參數。 使用此參數來顯示詳細的記錄。
-WhatIf
一般參數。 使用此開關來測試及驗證您的輸入參數,而不需要實際啟用監視。
輸出
成功啟用的範例輸出
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
Disable-InstrumentationEngine
藉由移除一些登錄機碼來停用檢測引擎。 請重新啟動 IIS 讓變更生效。
範例
Disable-InstrumentationEngine
參數
-Verbose
一般參數。 使用此參數來輸出詳細的記錄。
輸出
成功停用檢測引擎的範例輸出
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...
Disable-ApplicationInsightsMonitoring
停用目標電腦上的監視。 此 Cmdlet 會移除對 IIS applicationHost.config 的編輯,並且移除登錄機碼。
範例
Disable-ApplicationInsightsMonitoring
參數
-Verbose
一般參數。 使用此參數來顯示詳細的記錄。
輸出
成功停用監視的範例輸出
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
取得組態檔,並將值列印至主控台。
範例
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: .*
Get-ApplicationInsightsMonitoringStatus
此 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
在此範例中:
電腦識別碼是匿名識別碼,用來唯一識別您的伺服器。 如果您建立支援要求,我們需要此識別碼來尋找伺服器的記錄。
預設網站在 IIS 中已停止
IIS 顯示 DemoWebApp111 已啟動,但應用程式未收到任何要求。 報告顯示沒有執行中的程序 (ProcessId:找不到)。
DemoWebApp222 正在執行中且正在監視中 (檢測:true)。 根據使用者設定,檢測金鑰 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 應用程式。
範例:PowerShell 模組資訊
執行 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 應用程式的監視狀態。 使用此選項可檢閱您的應用程式是否已成功檢測。 您也可以檢閱哪些檢測金鑰符合您的網站。
-PowerShellModule
選擇性。 使用此參數來報告監視所需的 DLL 版本號碼和路徑。 如果您需要識別任何 DLL 的版本,包括 Application Insights SDK,請使用此選項。
-InspectProcess
選擇性。 使用此參數來報告 IIS 是否正在執行。 其會下載外部工具,以判斷是否已將必要的 DLL 載入 IIS 執行階段。
如果此程序因任何原因而失敗,您可以手動執行下列命令:
iisreset.exe /status[handle64.exe](/sysinternals/downloads/handle) -p w3wp | findstr /I "InstrumentationEngine AI. ApplicationInsights"[listdlls64.exe](/sysinternals/downloads/listdlls) w3wp | findstr /I "InstrumentationEngine AI ApplicationInsights"
-力量
選擇性。 僅用於 InspectProcess。 使用此參數可略過在下載更多工具之前出現的使用者提示。
Set-ApplicationInsightsMonitoringConfig
設定組態檔,而不執行完整重新安裝。 請重新啟動 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'}})
參數
-InstrumentationKey
必要。 使用此參數來提供單一檢測金鑰,以供目標電腦上的所有應用程式使用。
-InstrumentationKeyMap
必要。 使用此參數來提供多個檢測金鑰,以及每個應用程式所使用的檢測金鑰組應。
您可以藉由設定 MachineFilter 來建立數部電腦的單一安裝指令碼。
重要
應用程式會以您提供時的順序比對規則。 請先指定最特定的規則,最後指定最通用的規則。
重要
InstrumentationKeyMap 是一項進階路由功能,會將同一部機器上的 Internet Information Services (IIS) 應用程式對應到 Application Insights 資源。 此功能適用於 Application Insights 代理程式自動檢測的 IIS 裝載 ASP.NET 和 ASP.NET Core 應用程式。
比對的運作方式
- 此地圖會定義名為
filters之規則的排序清單。 第一個相符的規則會生效。 先放置特定規則,最後再放置一條通用規則。 - 每個規則都可以將不同的 Application Insights 資源指派給相符的應用程式。 在支援的案例中建議使用連接字串,因為檢測金鑰為舊版。
可用的篩選
-
MachineFilter或machineFilter:會比對電腦或虛擬機器 (VM) 名稱的 C# 規則運算式。.*會比對所有名稱。 -
AppFilter或appFilter:會比對 IIS 網站名稱 (HostingEnvironment.SiteName) 的 C# 規則運算式。 未提供VirtualPathFilter或virtualPathFilter時,需要此篩選。 -
VirtualPathFilter或virtualPathFilter:會比對 IIS 虛擬路徑 (HostingEnvironment.ApplicationVirtualPath) 的 C# 規則運算式。 使用此篩選以鎖定網站下的單一應用程式。
術語對應
- PowerShell Cmdlet 使用
MachineFilter、AppFilter和VirtualPathFilter。 - Azure VM 和虛擬機器擴展集延伸模組 JSON 會使用
machineFilter、appFilter和virtualPathFilter,並以instrumentationSettings設定資源。
小提示
請納入會比對所有應用程式的最終規則 (例如 .*),並套用預設資源以讓行為變得明確。
此 Cmdlet 的對應形狀
- 提供
-InstrumentationKeyMap作為雜湊表的 PowerShell 陣列。 - 針對此 Cmdlet,以
InstrumentationSettings=@{ InstrumentationKey = '<ikey>' }設定每個規則的目標資源。 - 如果您想為機器上的所有應用程式使用單一資源,請改為使用
-ConnectionString或-InstrumentationKey。
Start-ApplicationInsightsMonitoringTrace
收集無程式碼連結執行階段所發出的 Windows 事件追蹤 (ETW) 事件 (部分機器翻譯)。 使用此 Cmdlet 作為比執行 PerfView (英文) 更簡單的替代方案。
事件會即時列印到主控台,並且也會寫入到 .etl 檔案。 您可以使用 PerfView 開啟 .etl 檔案,以進行更深入的分析。
此 Cmdlet 會一直執行到逾時 (預設值為 5 分鐘) 為止,或執行到您以 Ctrl + C 手動停止為止。
範例
如何收集事件
當您需要調查未檢測 IIS 應用程式的原因時,請使用此流程。
無程式碼連結執行階段會在 IIS 啟動時和應用程式啟動時發出 ETW 事件。
- 在系統管理命令提示字元中,執行
iisreset /stop以停止 IIS 及所有 Web 應用程式。 - 執行此 Cmdlet 開始進行追蹤。
- 在系統管理命令提示字元中,執行
iisreset /start以啟動 IIS。 - 瀏覽至應用程式以觸發啟動作業。
- 應用程式載入完成後,按
Ctrl + C加以停止,或等待逾時來結束工作階段。
要收集哪些事件
您可以選擇要包含的事件來源:
-
-CollectSdkEvents會從 Application Insights SDK 收集事件。 -
-CollectRedfieldEvents會從 Application Insights 代理程式與 Redfield 執行階段收集事件,這適用於 IIS 和應用程式啟動診斷。 - 指定這兩個參數來同時收集這兩組事件。
- 如果您未指定參數,則預設會收集這兩組參數。
參數
-最大持續時間(分鐘)
選擇性。 設定要收集多久才會逾時。預設值為 5 分鐘。
-LogDirectory
選擇性。 應寫入 .etl 檔案的目錄。 根據預設,檔案會建立到模組 PowerShell 目錄下。 工作階段啟動時會顯示完整路徑。
-CollectSdkEvents
選擇性。 包含 Application Insights SDK 事件。
-CollectRedfieldEvents
選擇性。 包含來自 Application Insights 代理程式與 Redfield 執行階段的事件。
-Verbose
一般參數。 輸出詳細記錄。
輸出
應用程式啟動記錄的範例
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
意見反應
此頁面對您有幫助嗎?
No
需要本主題的協助嗎?
想要嘗試使用 Ask Learn 來釐清或引導您完成本主題嗎?
其他資源
-
Last updated on
2025-10-13