ARM テンプレートと Windows 診断拡張機能を使用して、Windows VM ゲスト OS メトリックを Azure Monitor メトリック ストアに送信する

Azure Monitor エージェント (AMA) は、Azureおよびハイブリッド仮想マシンのゲスト オペレーティング システムから監視データを収集し、Microsoft Sentinelのサービスで使用するためにAzure Monitorに提供します>Microsoft Defender for Cloud。

Azure Monitor エージェントを使用して、Virtual Machinesからログとメトリックを収集することをお勧めします。 詳細については、「Azure Monitor エージェントの概要を参照してください。

Azure仮想マシン (VM) のゲスト OS からのパフォーマンス データは、他の platform メトリックと同様に自動的に収集されません。 Azure Monitor Diagnostics 拡張機能をインストールして、ゲスト OS メトリックをメトリック データベースに収集し、Azure Monitor メトリックのすべての機能で使用できるようにします。 これらの機能には、ほぼリアルタイムのアラート、グラフ作成、ルーティング、REST API からのアクセスなどがあります。 この記事では、Azure Resource Manager テンプレート (ARM テンプレート) を使用して、Windows VM のゲスト OS パフォーマンス メトリックをメトリック データベースに送信するプロセスについて説明します。

Important

Azure Diagnostics拡張機能は2026年3月31日に非推奨となり、サポートされていません。 拡張機能の新しいデプロイは推奨されません。 継続的なサポートと新機能へのアクセスを確保するには、ここで推奨される代替ソリューションに移行します

Azure ポータルを使用してゲスト OS メトリックを収集するように診断拡張機能を構成する方法の詳細については、「Windows Azure Diagnostics (WAD) 拡張機能のインストールと構成を参照してください。

ARM テンプレートを初めて利用する場合は、テンプレートのデプロイとその構造および構文についてご確認ください。

[前提条件]

データ シンクとしてAzure Monitorを設定する

Azure Diagnostics拡張機能では、data sinks と呼ばれる機能を使用して、メトリックとログをさまざまな場所にルーティングします。 次の手順では、ARM テンプレートと PowerShell を使用して、新しいAzure Monitor データ シンクを使用して VM をデプロイする方法を示します。

ARM テンプレート

この例では、公開されているサンプル テンプレートを使用できます。 開始テンプレートは GitHub にあります。

  • Azuredeploy.json: VM のデプロイ用に事前構成済みの ARM テンプレート。
  • Azuredeploy.parameters.json: VM 用に設定するユーザー名やパスワードなどの情報が格納されているパラメーター ファイル。 デプロイ中、このファイルで設定されているパラメーターが、ARM テンプレートによって使用されます。

両方のファイルをダウンロードし、ローカルに保存します。

azuredeploy.parameters.json ファイルを更新する

  1. azuredeploy.parameters.json ファイルを開きます。

  2. VM の adminUsernameadminPassword について値を入力します。 これらのパラメーターは VM へのリモート アクセスに使用されます。 お使いの VM がハイジャックされないように、このテンプレートの値は使用 "しないでください"。 ボットは、パブリック GitHub リポジトリ内のユーザー名とパスワードをインターネットでスキャンします。 多くの場合、このようなボットは、これらの既定値を使用して VM をテストします。

  3. VM について一意の dnsname を作成します。

azuredeploy.json を変更する

  1. azuredeploy.json ファイルを開きます。

  2. ストレージ アカウント ID を、テンプレートの variables セクションの、storageAccountName エントリの後ろに追加します。

    // Find these lines.
    "variables": {
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sawinvm')]",
    
    // Add this line directly below.
        "accountid": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
    
  3. このマネージド サービス ID (MSI) 拡張機能を、テンプレートの resources セクションの先頭に追加します。 拡張機能により、Azure Monitorが出力されるメトリックを受け入れることが保証されます。

    //Find this code.
    "resources": [
    // Add this code directly below.
        {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('vmName'), '/', 'WADExtensionSetup')]",
            "apiVersion": "2017-12-01",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" ],
            "properties": {
                "publisher": "Microsoft.ManagedIdentity",
                "type": "ManagedIdentityExtensionForWindows",
                "typeHandlerVersion": "1.0",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "port": 50342
                }
            }
        },
    
  4. identity 構成を VM リソースに追加して、Azureが MSI 拡張機能にシステム ID を割り当てられるようにします。 この手順により、VM が自身に関するゲスト メトリックをAzure Monitorに出力できるようになります。

    // Find this section
                    "subnet": {
                "id": "[variables('subnetRef')]"
                }
            }
            }
        ]
        }
    },
    {
        "apiVersion": "2017-03-30",
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[variables('vmName')]",
        "location": "[resourceGroup().location]",
        // add these 3 lines below
        "identity": {
        "type": "SystemAssigned"
        },
        //end of added lines
        "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
        "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
        ],
        "properties": {
        "hardwareProfile": {
        ...
    
  5. Windows VM で診断拡張機能を有効にするには、次の構成を追加します。 単純なResource Managerベースの VM の場合は、VM のリソース配列に拡張機能の構成を追加できます。 行 "sinks": "AzMonSink"、およびこのセクション内にある対応する "SinksConfig" は、拡張機能がメトリックを直接 Azure Monitor に出力できるようにします。 必要に応じて、パフォーマンス カウンターを自由に追加または削除してください。

            "networkProfile": {
                "networkInterfaces": [
                {
                    "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
                }
                ]
            },
    "diagnosticsProfile": {
        "bootDiagnostics": {
        "enabled": true,
        "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob]"
        }
    }
    },
    //Start of section to add
    "resources": [
    {
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "name": "[concat(variables('vmName'), '/', 'Microsoft.Insights.VMDiagnosticsSettings')]",
                "apiVersion": "2017-12-01",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
                ],
                "properties": {
                "publisher": "Microsoft.Azure.Diagnostics",
                "type": "IaaSDiagnostics",
                "typeHandlerVersion": "1.12",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "WadCfg": {
                    "DiagnosticMonitorConfiguration": {
        "overallQuotaInMB": 4096,
        "DiagnosticInfrastructureLogs": {
                        "scheduledTransferLogLevelFilter": "Error"
            },
                        "Directories": {
                        "scheduledTransferPeriod": "PT1M",
        "IISLogs": {
                            "containerName": "wad-iis-logfiles"
                        },
                        "FailedRequestLogs": {
                            "containerName": "wad-failedrequestlogs"
                        }
                        },
                        "PerformanceCounters": {
                        "scheduledTransferPeriod": "PT1M",
                        "sinks": "AzMonSink",
                        "PerformanceCounterConfiguration": [
                            {
                            "counterSpecifier": "\\Memory\\Available Bytes",
                            "sampleRate": "PT15S"
                            },
                            {
                            "counterSpecifier": "\\Memory\\% Committed Bytes In Use",
                            "sampleRate": "PT15S"
                            },
                            {
                            "counterSpecifier": "\\Memory\\Committed Bytes",
                            "sampleRate": "PT15S"
                            }
                        ]
                        },
                        "WindowsEventLog": {
                        "scheduledTransferPeriod": "PT1M",
                        "DataSource": [
                            {
                            "name": "Application!*"
                            }
                        ]
                        },
                        "Logs": {
                        "scheduledTransferPeriod": "PT1M",
                        "scheduledTransferLogLevelFilter": "Error"
                        }
                    },
                    "SinksConfig": {
                        "Sink": [
                        {
                            "name" : "AzMonSink",
                            "AzureMonitor" : {}
                        }
                        ]
                    }
                    },
                    "StorageAccount": "[variables('storageAccountName')]"
                },
                "protectedSettings": {
                    "storageAccountName": "[variables('storageAccountName')]",
                    "storageAccountKey": "[listKeys(variables('accountid'),'2015-06-15').key1]",
                    "storageAccountEndPoint": "https://core.windows.net/"
                }
                }
            }
            ]
    //End of section to add
    
  6. 両方のファイルを保存して閉じます。

ARM テンプレートをデプロイする

Azure Diagnosticsの拡張機能バージョン1.5以降を実行している必要があり、かつARMテンプレートでプロパティをautoUpgradeMinorVersion:に設定する必要があります。 Azure、VM の起動時に適切な拡張機能を読み込みます。 ご自身のテンプレートにこれらの設定がない場合は、テンプレートを変更して再デプロイします。

ARM テンプレートをデプロイするには、Azure PowerShellを使用します。

  1. PowerShell を起動します。

  2. Login-AzAccount を使用してAzureにサインインします。

  3. Get-AzSubscription を使用して、サブスクリプションの一覧を取得します。

  4. VM を作成または更新するために使用しているサブスクリプションを設定します。

    Select-AzSubscription -SubscriptionName "<Name of the subscription>"
    
  5. デプロイする VM の新しいリソース グループを作成するために、次のコマンドを実行します。

    New-AzResourceGroup -Name "<Name of Resource Group>" -Location "<Azure Region>"
    

    カスタム メトリックに対して有効になっているAzureリージョンを使用することを忘れないでください。

  6. 次のコマンドを実行して、ARM テンプレートを使用して VM をデプロイします。

    既存の VM を更新する場合は、-Mode Incremental を以下のコマンドの末尾に追加します。

    New-AzResourceGroupDeployment -Name "<NameThisDeployment>" -ResourceGroupName "<Name of the Resource Group>" -TemplateFile "<File path of your Resource Manager template>" -TemplateParameterFile "<File path of your parameters file>"
    
  7. デプロイが成功すると、VM が Azure ポータルに表示され、メトリックがAzure Monitorに出力されます。

    選択した vmSkuSize に関連するエラーが発生することがあります。 このエラーが発生した場合は、azuredeploy.json ファイルに戻り、vmSkuSize パラメーターの既定値を更新します。 この場合は、 "Standard_DS1_v2"を試してみることをお勧めします。

メトリックをグラフ化する

  1. Azure ポータルにサインインします。

  2. 左側のメニューで [モニター] を選択します。

  3. [モニター] ページで、 [メトリック] を選択します。

    [メトリック] ページを示すスクリーンショット。

  4. 集計の期間を [過去 30 分間] に変更します。

  5. リソースのドロップダウン メニューで、作成した VM を選択します。 テンプレートの名前を変更しなかった場合は、SimpleWinVM2 のはずです。

  6. 名前空間のドロップダウン リストで、azure.vm.windows.guestmetrics を選択します。

  7. メトリックのドロップダウン リストで、Memory%Committed Bytes in Use を選択します。

次のステップ

カスタム メトリックの詳細を確認します。