共用方式為


為本地伺服器部署 Azure 監視器 Application Insights 代理程式

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

Application Insights 代理程式位於 PowerShell 資源庫

PowerShell 資源庫圖示。

說明

  • 若要開始使用精簡的程式碼範例,請參閱 [開始使用] 索引標籤。
  • 如需深入了解如何開始使用,請參閱 [詳細指示] 索引標籤。
  • 如需 PowerShell API 參考,請參閱 [API 參考] 索引標籤。
  • 如需版本資訊更新,請參閱 [發行備註] 索引標籤。

此索引標籤包含應適用於大部分環境的快速入門命令。 這些指令仰賴 PowerShell Gallery 散發更新。 這些命令支援 PowerShell -Proxy 參數。

如需這些命令的說明、自訂指示以及疑難排解的相關資訊,請參閱詳細指示

如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶

透過 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

附註

AllowPrerelease Cmdlet 中的 Install-Module 切換可用於安裝搶鮮版 (Beta)。

如需詳細資訊,請參閱 Install-Module

啟用監視

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/'