このタブでは、ApplicationMonitor モジュールを PowerShell ギャラリーにオンボードしてダウンロードする方法を詳しく説明します。
始めるために必要になる最も一般的なパラメーターが含まれています。
インターネットにアクセスできない場合の手動によるダウンロード手順も説明されています。
接続文字列を取得する
開始するには、接続文字列が必要です。 詳細については、接続文字列に関するページを参照してください。
Note
インストルメンテーション キーのインジェストのサポートは、2025 年 3 月 31 日に終了します。 インストルメンテーション キーのインジェストは引き続き機能しますが、この機能の更新プログラムやサポートは提供されなくなります。 接続文字列に移行することで、新機能をご利用いただけます。
管理者として昇格された実行ポリシーで PowerShell を実行します。
管理者として実行
PowerShell でコンピューターに対して変更を行うには、管理者レベルのアクセス許可が必要です。
実行ポリシー
エラーの例
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 ギャラリーからモジュールをダウンロードするために、サーバーを準備します。
Note
PowerShell ギャラリーは、Windows 10、Windows Server 2016、および PowerShell 6 以上でサポートされています。
以前のバージョンについては、「PowerShellGet のインストール」を参照してください。
管理者として昇格された実行ポリシーで PowerShell を実行します。
NuGet パッケージ プロバイダーをインストールします。
- 説明:PowerShellGallery などの NuGet ベースのリポジトリとやり取りするには、このプロバイダーが必要です
- リファレンス: 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 ギャラリーから他のモジュールを取得するために使用されるツールが含まれます。 バージョン 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 を再起動します。 現在のセッションで新しいバージョンを読み込むことはできません。 新しい PowerShell セッションでは、最新バージョンの PowerShellGet が読み込まれます。
PowerShell ギャラリーからモジュールをダウンロードしてインストールする
次の手順では、PowerShell ギャラリーから Az.ApplicationMonitor モジュールをダウンロードします。
- PowerShell ギャラリーのすべての前提条件が満たされていることを確認します。
- 管理者として昇格された実行ポリシーで PowerShell を実行します。
- Az.ApplicationMonitor モジュールをインストールします。
- リファレンス: Install-Module。
- コマンド:
Install-Module -Name Az.ApplicationMonitor
。
- 省略可能なパラメーター:
-Proxy
要求用のプロキシ サーバーを指定します。
-AllowPrerelease
アルファ リリースとベータ リリースのインストールを許可します。
-AcceptLicense
"ライセンス条項に同意する" のプロンプトをバイパスします
-Force
"信頼されていないリポジトリ" の警告をバイパスします。
モジュールを手動でダウンロードしてインストールする (オフライン オプション)
何らかの理由で、PowerShell モジュールに接続できない場合は、Az.ApplicationMonitor モジュールを手動でダウンロードしてインストールすることができます。
最新の nupkg ファイルを手動でダウンロードする
- https://www.powershellgallery.com/packages/Az.ApplicationMonitor にアクセスします。
- 「Version History (バージョン履歴) 」一覧から最新バージョンのファイルを選択します。
- 「Installation Options (インストール オプション) 」の「Manual Download (手動ダウンロード) 」を選択します。
オプション 1: PowerShell モジュールのディレクトリにインストールする
手動でダウンロードした PowerShell モジュールを PowerShell ディレクトリにインストールし、PowerShell セッションで検出できるようにします。
詳細については、「PowerShell モジュールをインストールする」を参照してください。
Expand-Archive (v1.0.1.0) を使用して zip ファイルとして nupkg を解凍する
説明: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 を解凍する
説明:拡張子を変更せずに nupkg ファイルを解凍するには、最新バージョンの Expand-Archive を使用します。
リファレンス: 「Expand-Archive」と「Microsoft.PowerShell.Archive」。
コマンド:
$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
を使用してモジュールを読み込みます。
プロキシを経由するトラフィックのルーティング
非公開イントラネット上のコンピューターを監視するときは、プロキシ経由で HTTP トラフィックをルーティングする必要があります。
Az.ApplicationMonitor を PowerShell ギャラリーからダウンロードしてインストールする PowerShell コマンドでは、-Proxy
パラメーターがサポートされています。
インストール スクリプトを作成するときは、上記の手順を確認します。
Application Insights SDK では、アプリのテレメトリを Microsoft に送信する必要があります。 web.config ファイルでアプリのプロキシ設定を構成することをお勧めします。 詳細については、「プロキシ パススルーを実現するにはどうすればよいですか?」を参照してください。
監視を有効にする
モニターを有効にするには Enable-ApplicationInsightsMonitoring
コマンドを使用します。
このコマンドレットの使用方法の詳細については、API リファレンスに関する記事を参照してください。
このタブでは、Az.ApplicationMonitor PowerShell モジュールのメンバーである次のコマンドレットについて説明します。
Note
- 開始するには、接続文字列が必要です。 詳細については、リソースの作成に関するページを参照してください。
- このコマンドレットでは、ライセンスおよびプライバシーに関する声明を確認して同意する必要があります。
Note
インストルメンテーション キーのインジェストのサポートは、2025 年 3 月 31 日に終了します。 インストルメンテーション キーのインジェストは引き続き機能しますが、この機能の更新プログラムやサポートは提供されなくなります。 接続文字列に移行することで、新機能をご利用いただけます。
重要
このコマンドレットでは、管理者権限と昇格された実行ポリシーを備えた PowerShell セッションが必要です。 詳細については、昇格された実行ポリシーを備えた管理者として PowerShell を実行する方法に関するページを参照してください。
- このコマンドレットでは、ライセンスおよびプライバシーに関する声明を確認して同意する必要があります。
- インストルメンテーション エンジンを使用するとオーバーヘッドが増加します。これは、既定ではオフになっています。
Enable-InstrumentationEngine
いくつかのレジストリ キーを設定することで、インストルメンテーション エンジンを有効にします。
変更を有効にするために IIS を再起動してください。
インストルメンテーション エンジンは、.NET SDK によって収集されたデータを補完できます。
これは、マネージド プロセスの実行を説明するイベントおよびメッセージを収集します。 これらのイベントとメッセージには、依存関係の結果コード、HTTP 動詞、SQL コマンド テキストが含まれます。
インストルメンテーション エンジンは、次の場合に有効にします。
- Enable コマンドレットを使用して監視を既に有効にしているが、インストルメンテーション エンジンは有効にしていなかった場合。
- .NET SDK を使用してアプリを手動でインストルメント化しており、追加のテレメトリを収集する必要がある。
例
Enable-InstrumentationEngine
パラメーター
-AcceptLicense
省略可能。 ヘッドレス インストールでライセンスおよびプライバシーに関する声明に同意する場合は、このスイッチを使用します。
-Verbose
共通パラメーター。 詳細なログを出力する場合はこのスイッチを使用します。
出力
インストルメンテーション エンジンが正常に有効化された場合の出力例
Configuring IIS Environment for instrumentation engine...
Configuring registry for instrumentation engine...
Enable-ApplicationInsightsMonitoring
ターゲット コンピューターで IIS アプリのコード不要のアタッチ監視を有効にします。
このコマンドレットにより、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'}})
注意
このコンテキストでの AppFilter の名前付けは混乱を招く可能性があり、AppFilter
で、アプリケーション名の regex フィルター (IIS の .NET の場合は HostingEnvironment.SiteName) が設定されます。 VirtualPathFilter
で、仮想パス regex フィルター (IIS の .NET の場合は HostingEnvironment.ApplicationVirtualPath) が設定されます。 1 つのアプリをインストルメント化するには、VirtualPathFilter を次のように使用します: Enable-ApplicationInsightsMonitoring -InstrumentationKeyMap @(@{VirtualPathFilter="^/MyAppName$"; InstrumentationSettings=@{InstrumentationKey='<your ikey>'}})
パラメーター
-ConnectionString
必須。 このパラメーターを使用して、ターゲット コンピューター上のすべてのアプリによって使用される単一の接続文字列を指定します。
-InstrumentationKey
必須。 このパラメーターを使用して、ターゲット コンピューター上のすべてのアプリによって使用される単一のインストルメンテーション キーを指定します。
-InstrumentationKeyMap
必須。 このパラメーターを使用して、複数のインストルメンテーション キーのほか、各アプリによって使用されるインストルメンテーション キーのマッピングを指定します。
MachineFilter
を設定することで、複数のコンピューター用に単一のインストール スクリプトを作成できます。
重要
アプリは、規則が指定された順番で規則と照合されます。 そのため、最も具体的な規則を最初に指定し、最も一般的な規則を最後に指定する必要があります。
スキーマ
@(@{MachineFilter='.*';AppFilter='.*';InstrumentationSettings=@{InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}})
- MachineFilter は、コンピューターまたは VM 名に必要な C# の正規表現です。
- '.*' は、すべてに一致します
- 'ComputerName' は、指定したものと完全に同じ名前を持つコンピューターのみに一致します。
- AppFilter は、IIS サイト名に必要な C# の正規表現です。 get-iissite コマンドを実行することで、ご利用のサーバー上でサイトのリストを入手できます。
- '.*' は、すべてに一致します
- 'SiteName' は、指定したものと完全に同じ名前を持つ IIS サイトのみに一致します。
- InstrumentationKey は上記の 2 つのフィルターに一致するアプリの監視を有効にするために必要です。
- 監視を除外する規則を定義したい場合は、この値を null のままにします。
-EnableInstrumentationEngine
省略可能。 インストルメンテーション エンジンを有効にして、マネージド プロセスの実行中に何が発生したかを示すイベントとメッセージを収集するには、このスイッチを使用します。 これらのイベントとメッセージには、依存関係の結果コード、HTTP 動詞、SQL コマンド テキストが含まれます。
インストルメンテーション エンジンを使用するとオーバーヘッドが増加します。これは、既定ではオフになっています。
-AcceptLicense
省略可能。 ヘッドレス インストールでライセンスおよびプライバシーに関する声明に同意する場合は、このスイッチを使用します。
-IgnoreSharedConfig
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
ターゲット コンピューターに対する監視を無効にします。
このコマンドレットにより、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
このコマンドレットは、Application Insights エージェントに関するトラブルシューティング情報を提供します。
このコマンドレットを使用すると、監視状態、PowerShell モジュールのバージョン、実行中のプロセスを調べることができます。
このコマンドレットにより、監視に必要なバージョン情報と主要なファイルに関する情報が報告されます。
例
例:アプリケーション ステータス
Web サイトの監視状態を表示するには、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
この例では、以下が表示されています。
Machine Identifier は、サーバーを一意に識別するために使用される匿名 ID です。 サポート リクエストを作成する場合、Microsoft ではお使いのサーバーのログを検索するのにこの ID が必要です。
Default Web Site は、IIS で停止されています
DemoWebApp111 は、IIS で開始されていますが、まだ要求を受信していません。 このレポートは実行中のプロセスがないことを示しています (ProcessId: not found)。
DemoWebApp222 は実行中で、監視されています (Instrumented: true)。 ユーザーの構成に基づいて、インストルメンテーション キー xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx123 がこのサイトと一致しています。
DemoWebApp333 は、Application Insights SDK を使用して手動でインストルメント化されています。 SDK が検出されたため、Application Insights エージェントではこのサイトを監視しません。
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
パラメーター
(パラメーターなし)
既定では、このコマンドレットによって Web アプリケーションの監視状態が報告されます。
アプリケーションが正常にインストルメント化されているかどうかを確認するには、このオプションを使用します。
また、どのインストルメンテーション キーがサイトに一致していたかを確認することもできます。
-PowerShellModule
オプション。 このスイッチを使用すると、監視に必要なバージョン番号と DLL のパスがレポートされます。
Application Insights SDK を含む任意の DLL のバージョンを特定する必要がある場合は、このオプションを使用します。
-InspectProcess
オプション。 このスイッチを使用すると、IIS が実行されているかどうかがレポートされます。
必要な DLL が IIS ランタイムに読み込まれているかどうかを確認するために、外部のツールがダウンロードされます。
何らかの理由でこのプロセスが失敗した場合は、次のコマンドを手動で実行できます。
- iisreset.exe /status
- handle64.exe -p w3wp | findstr /I "InstrumentationEngine AI. ApplicationInsights"
- listdlls64.exe w3wp | findstr /I "InstrumentationEngine AI ApplicationInsights"
-Force
オプション。 InspectProcess でのみ使用されます。 このスイッチは、追加のールがダウンロードされる前に表示されるユーザー プロンプトをスキップするために使用します。
Set-ApplicationInsightsMonitoringConfig
再インストールの全手順を実行せずに、構成ファイルを設定します。
変更を有効にするために IIS を再起動してください。
重要
このコマンドレットでは、管理者権限の 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
を設定することで、複数のコンピューター用に単一のインストール スクリプトを作成できます。
重要
アプリは、規則が指定された順番で規則と照合されます。 そのため、最も具体的な規則を最初に指定し、最も一般的な規則を最後に指定する必要があります。
スキーマ
@(@{MachineFilter='.*';AppFilter='.*';InstrumentationKey='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'})
- MachineFilter は、コンピューターまたは VM 名に必要な C# の正規表現です。
- '.*' は、すべてに一致します
- 'ComputerName' は、指定した名前を持つコンピューターのみに一致します。
- AppFilter は、コンピューターまたは VM 名に必要な C# の正規表現です。
- '.*' は、すべてに一致します
- 'ApplicationName' は、指定された名前を持つ IIS アプリのみに一致します。
- InstrumentationKey は上記の 2 つのフィルターに一致するアプリの監視を有効にするために必要です。
- 監視を除外する規則を定義したい場合は、この値を null のままにします。
-Verbose
共通パラメーター。 詳細なログを表示するにはこのスイッチを使用します。
出力
既定では出力はありません。
-InstrumentationKey を使用して構成ファイルを設定した場合の詳細出力の例
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
-InstrumentationKeyMap を使用して構成ファイルを設定した場合の詳細出力の例
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
Start-ApplicationInsightsMonitoringTrace
コードなしの接続ランタイムから ETW イベントを収集します。
このコマンドレットは、PerfView を実行する代わりの手段です。
イベントが収集され、リアルタイムでコンソールに出力され、ETL ファイルに保存されます。 さらに調査するために、PerfView を使用して 出力 ETL ファイルを開くことができます。
このコマンドレットは、タイムアウト期間 (既定値は 5 分) に達するか、手動で停止 (Ctrl + C
) されるまで実行されます。
例
イベントの収集方法
通常、ご利用のアプリケーションがインストルメント化されている理由を調査するには、イベントの収集が求められます。
IIS が起動されとき、およびアプリケーションが起動されたとき、コードなしの接続ランタイムによって、ETW イベントが出力されます。
これらのイベントを収集するには
- 管理特権を使用したコマンド コンソールで、
iisreset /stop
を実行して IIS とすべての Web アプリを停止します。
- このコマンドレットを実行します。
- 管理特権を使用したコマンド コンソールで、
iisreset /start
を実行して IIS を開始します。
- アプリの参照を試みます。
- ご利用のアプリで読み込みが完了した後、手動で停止したり (
Ctrl + C
)、タイムアウトするまで待機したりすることができます。
収集するイベント
イベントを収集するときに、3 つのオプションが用意されています。
- スイッチ
-CollectSdkEvents
を使用して、Application Insights SDK から出力されたイベントを収集します。
- スイッチ
-CollectRedfieldEvents
を使用して、Application Insights エージェントと Redfield ランタイムによって出力されたイベントを収集します。 これらのログは、IIS とアプリケーションの起動を診断するときに役立ちます。
- 両方のスイッチを使用して、両方のイベントの種類を収集します。
- 既定では、スイッチが指定されていない場合、両方のイベントの種類が収集されます。
パラメーター
-MaxDurationInMinutes
省略可能。 このパラメーターを使用して、このスクリプトでイベントが収集される時間を設定します。 既定値は 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
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...