この記事では、Azure 仮想マシン、仮想マシン スケール セット、Azure Arc 対応サーバーに Azure Monitor エージェント をインストール、アンインストール、更新、構成するために使用できるさまざまな方法について説明します。
前提条件
Azure Monitor エージェントを使用するための前提条件やその他の要件については、以下の記事を参照してください。
重要
Azure Monitor エージェントのインストール、アップグレード、またはアンインストールで、マシンを再起動する必要はありません。
 
インストール オプション
Azure VM と Azure Arc 対応サーバーに Azure Monitor エージェントをインストールするときのオプションを次の表に示します。
Azure にないマシンの場合は、 Azure Monitor エージェント をインストールする前に、そのマシンに Azure Arc エージェントをインストールする必要があります。
| インストール方法 | 説明 | 
| 仮想マシン (VM) 拡張機能 | この記事で説明しているいずれかの方法を使用して、Azure 拡張機能フレームワーク経由でエージェントをインストールします。 この方法では DCR は作成されないため、データ収集を開始する前に少なくとも 1 つの DCR を作成して、それをエージェントに関連付ける必要があります。 | 
| DCR を作成する | Azure portal で DCR を作成すると、DCR のリソースとして追加されたすべてのマシンに Azure Monitor エージェントがインストールされます。 エージェントは、DCR で定義されているとおりにデータの収集を直ちに開始します。 | 
| VM の分析情報 | マシン上で VM Insights を有効にすると、Azure Monitor エージェントがインストールされ、定義済みのデータ セットを収集するための DCR が作成されます。 この DCR は変更しないでください。ただし、より多くのデータを収集するために追加の DCR を作成することはできます。 | 
| コンテナーの分析情報 | Kubernetes クラスターで Prometheus メトリックまたはコンテナー ログの収集を有効にすると、コンテナー化されたバージョンの Azure Monitor エージェントがクラスターにインストールされ、データの収集をすぐに開始するために DCR が作成されます。 DCR を変更するには、「DCR を使用して Container insights でデータ収集とコストの最適化を構成する」のガイダンスを使用します。 | 
| クライアント インストーラー | Windows 11 および Windows 10 のクライアント用の Windows MSI インストーラーを使用してエージェントをインストールします。 | 
| Azure Policy | Azure Policy を使用して、Azure 仮想マシンと Azure Arc 対応サーバーにエージェントを自動的にインストールし、それらを必要な DCR に自動的に関連付けます。 | 
注
- テナント間でデータを送信するには、まず Azure Lighthouse を有効にする必要があります。 
- Azure Monitor エージェントがインストールされたマシンの複製はサポートされていません。 このシナリオのベスト プラクティスは、 Azure Policy またはコードとしてのインフラストラクチャ (IaaC) ツールを使用して、Azure Monitor エージェントを大規模にデプロイすることです。 
 
エージェント拡張機能をインストールする
仮想マシン拡張機能を追加するための PowerShell コマンドを使用して、Azure 仮想マシンまたは Azure Arc 対応サーバーに Azure Monitor エージェントをインストールできます。
Azure 仮想マシン
次の PowerShell コマンドを使用して、Azure 仮想マシンに Azure Monitor エージェントをインストールします。 使用する認証方法に基づいて適切なコマンドを選択してください。
- ウィンドウズ - ## User-assigned managed identity
Set-AzVMExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <___location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true -SettingString '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":"/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
## System-assigned managed identity
Set-AzVMExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <___location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
 
- Linux - ## User-assigned managed identity
Set-AzVMExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <___location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true -SettingString '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
## System-assigned managed identity
Set-AzVMExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <___location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
 
Azure 仮想マシン スケール セット
              Add-AzVmssExtension PowerShell コマンドレットを使用して、Azure Monitor エージェントを Azure 仮想マシン スケール セットにインストールします。
Azure Arc 対応サーバー
次の PowerShell コマンドを使用して、Azure Arc 対応サーバーに Azure Monitor エージェントをインストールします。
- ウィンドウズ - New-AzConnectedMachineExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -MachineName <arc-server-name> -Location <arc-server-___location> -EnableAutomaticUpgrade
 
- Linux - New-AzConnectedMachineExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -MachineName <arc-server-name> -Location <arc-server-___location> -EnableAutomaticUpgrade
 
仮想マシン拡張機能を追加するための Azure CLI コマンドを使用して、Azure 仮想マシンまたは Azure Arc 対応サーバーに Azure Monitor エージェントをインストールできます。
Azure 仮想マシン
次の Azure CLI コマンドを使用して、Azure 仮想マシンに Azure Monitor エージェントをインストールします。 使用する認証方法に基づいて適切なコマンドを選択してください。
ユーザー割り当てマネージド ID
- ウィンドウズ - az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true --settings '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":"/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
 
- Linux - az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true --settings '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":"/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
 
システム割り当てマネージド ID
- ウィンドウズ - az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true
 
- Linux - az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true
 
Azure 仮想マシン スケール セット
              az vmss 拡張機能セットの Azure CLI コマンドレットを使用して、Azure Monitor エージェントを Azure 仮想マシン スケール セットにインストールします。
Azure Arc 対応サーバー
次の Azure CLI コマンドを使用して、Azure Arc 対応サーバーに Azure Monitor エージェントをインストールします。
- ウィンドウズ - az connectedmachine extension create --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --type AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --___location <arc-server-___location> --enable-auto-upgrade true
 
- Linux - az connectedmachine extension create --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --type AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --___location <arc-server-___location> --enable-auto-upgrade true
 
Azure Resource Manager テンプレートを使用して Azure 仮想マシンまたは Azure Arc 対応サーバーに Azure Monitor エージェントをインストールし、DCR との関連付けを作成することができます。 DCR の関連付けを作成する前に、DCR を作成する必要があります。
エージェントをインストールし、関連付けを作成するためのサンプル テンプレートを次のリソースから取得します。
次のコマンドを含む Resource Manager テンプレートのデプロイ方法を使用して、テンプレートをインストールします。
- PowerShell - New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>" -TemplateParameterFile "<parameter-filename.json>"
 
- Azure CLI - az deployment group create --resource-group "<resource-group-name>" --template-file "<path-to-template>" --parameters "@<parameter-filename.json>"
 
 
アンインストール
Azure portal を使用して Azure Monitor エージェントをアンインストールするには、仮想マシン、スケール セット、または Azure Arc 対応サーバーに移動します。 [ 拡張機能 ] タブを選択し、 AzureMonitorWindowsAgent または AzureMonitorLinuxAgent を選択します。 開いたダイアログで、[アンインストール] を選択 します。
Azure 仮想マシンでのアンインストール
Azure 仮想マシン上の Azure Monitor エージェントをアンインストールするには、次の PowerShell コマンドを使用します。
- ウィンドウズ - Remove-AzVMExtension -Name AzureMonitorWindowsAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> 
 
- Linux - Remove-AzVMExtension -Name AzureMonitorLinuxAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> 
 
Azure 仮想マシン スケール セットでのアンインストール
              Remove-AzVmssExtension PowerShell コマンドレットを使用して、Azure 仮想マシン スケール セット上の Azure Monitor エージェントをアンインストールします。
Azure Arc 対応サーバーでのアンインストール
Azure Arc 対応サーバー上の Azure Monitor エージェントをアンインストールするには、次の PowerShell コマンドを使用します。
- ウィンドウズ - Remove-AzConnectedMachineExtension -MachineName <arc-server-name> -ResourceGroupName <resource-group-name> -Name AzureMonitorWindowsAgent
 
- Linux - Remove-AzConnectedMachineExtension -MachineName <arc-server-name> -ResourceGroupName <resource-group-name> -Name AzureMonitorLinuxAgent
 
Azure 仮想マシンでのアンインストール
Azure 仮想マシン上の Azure Monitor エージェントをアンインストールするには、次の Azure CLI コマンドを使用します。
- ウィンドウズ - az vm extension delete --resource-group <resource-group-name> --vm-name <virtual-machine-name> --name AzureMonitorWindowsAgent
 
- Linux - az vm extension delete --resource-group <resource-group-name> --vm-name <virtual-machine-name> --name AzureMonitorLinuxAgent
 
Azure 仮想マシン スケール セットでのアンインストール
              az vmss 拡張機能 delete Azure CLI コマンドレットを使用して、Azure 仮想マシン スケール セット上の Azure Monitor エージェントをアンインストールします。
Azure Arc 対応サーバーでのアンインストール
Azure Arc 対応サーバー上の Azure Monitor エージェントをアンインストールするには、次の Azure CLI コマンドを使用します。
- ウィンドウズ - az connectedmachine extension delete --name AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name>
 
- Linux - az connectedmachine extension delete --name AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name>
 
 
更新する
注
常に最新バージョンのエージェントに更新するか、 拡張機能の自動アップグレードを選択することを強くお勧めします。
拡張機能の自動ロールアウトは、最新バージョンのエージェントを安全にデプロイするために、標準的な Azure デプロイのプラクティスに従います。 自動更新では最新バージョンがロールアウトされるまで数週間かかることを想定する必要があります。
アップグレードは複数のバッチで発行されるため、一部の仮想マシン、スケール セット、または Azure Arc 対応サーバーが他のマシンやサーバーより先にアップグレードされる場合があります。
拡張機能を直ちにアップグレードする必要がある場合は、この記事で説明している手動の手順を使用できます。 過去 1 年間にリリースされたエージェントのみがサポートされます。
 
エージェントで 1 回限りの更新を行うには、まず既存のエージェント バージョンをアンインストールする必要があります。 次に、説明に従って新しいバージョンをインストールします。
拡張機能の自動アップグレードを有効にして、エージェントの 自動更新を有効にすることをお勧めします。 仮想マシンまたはスケール セットに移動し、[ 拡張機能 ] タブを選択し、 AzureMonitorWindowsAgent または AzureMonitorLinuxAgent を選択します。 開いたダイアログで、[ 自動アップグレードを有効にする] を選択します。
Azure 仮想マシンでの更新
エージェントのワンタイム更新を行うには、説明に従って新しいバージョンをインストールします。
拡張機能の自動アップグレードをオプトインして、エージェントの 自動更新を有効にすることをお勧めします。
次の PowerShell コマンドを使用します。
- ウィンドウズ - Set-AzVMExtension -ExtensionName AzureMonitorWindowsAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Publisher Microsoft.Azure.Monitor -ExtensionType AzureMonitorWindowsAgent -TypeHandlerVersion <version-number> -Location <___location> -EnableAutomaticUpgrade $true
 
- Linux - Set-AzVMExtension -ExtensionName AzureMonitorLinuxAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Publisher Microsoft.Azure.Monitor -ExtensionType AzureMonitorLinuxAgent -TypeHandlerVersion <version-number> -Location <___location> -EnableAutomaticUpgrade $true
 
Azure Arc 対応サーバーでの更新
エージェントで 1 回限りのアップグレードを実行するには、次の PowerShell コマンドを使用します。
- ウィンドウズ - $target = @{"Microsoft.Azure.Monitor.AzureMonitorWindowsAgent" = @{"targetVersion"=<target-version-number>}}
Update-AzConnectedExtension -ResourceGroupName $env.ResourceGroupName -MachineName <arc-server-name> -ExtensionTarget $target
 
- Linux - $target = @{"Microsoft.Azure.Monitor.AzureMonitorLinuxAgent" = @{"targetVersion"=<target-version-number>}}
Update-AzConnectedExtension -ResourceGroupName $env.ResourceGroupName -MachineName <arc-server-name> -ExtensionTarget $target
 
拡張機能の自動アップグレードをオプトインして、エージェントの 自動更新を有効にすることをお勧めします。
次の PowerShell コマンドを使用します。
- ウィンドウズ - Update-AzConnectedMachineExtension -ResourceGroup <resource-group-name> -MachineName <arc-server-name> -Name AzureMonitorWindowsAgent -EnableAutomaticUpgrade
 
- Linux - Update-AzConnectedMachineExtension -ResourceGroup <resource-group-name> -MachineName <arc-server-name> -Name AzureMonitorLinuxAgent -EnableAutomaticUpgrade
 
Azure 仮想マシンでの更新
エージェントで 1 回限りの更新を行うには、まず既存のエージェント バージョンをアンインストールする必要があります。 次に、この記事の説明に従って新しいバージョンをインストールします。
次の Azure CLI コマンドを使用して拡張機能の 自動アップグレード 機能をオプトインして、エージェントの自動更新を有効にすることをお勧めします。
- ウィンドウズ - az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --vm-name <virtual-machine-name> --resource-group <resource-group-name> --enable-auto-upgrade true
 
- Linux - az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --vm-name <virtual-machine-name> --resource-group <resource-group-name> --enable-auto-upgrade true
 
Azure Arc 対応サーバーでの更新
エージェントで 1 回限りのアップグレードを実行するには、次の Azure CLI コマンドを使用します。
- ウィンドウズ - az connectedmachine upgrade-extension --extension-targets "{\"Microsoft.Azure.Monitor.AzureMonitorWindowsAgent\":{\"targetVersion\":\"<target-version-number>\"}}" --machine-name <arc-server-name> --resource-group <resource-group-name>
 
- Linux - az connectedmachine upgrade-extension --extension-targets "{\"Microsoft.Azure.Monitor.AzureMonitorLinuxAgent\":{\"targetVersion\":\"<target-version-number>\"}}" --machine-name <arc-server-name> --resource-group <resource-group-name>
 
拡張機能の自動アップグレードをオプトインして、エージェントの 自動更新を有効にすることをお勧めします。
以下の Azure CLI コマンドを使用します。
- ウィンドウズ - az connectedmachine extension update --name AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --enable-auto-upgrade true
 
- Linux - az connectedmachine extension update --name AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --enable-auto-upgrade true
 
 
              データ収集規則 (DCR) は 、マシン上の Azure Monitor エージェントの管理ツールとして機能します。 AgentSettings DCR を使用して、特定の Azure Monitor エージェント パラメーターを構成して、特定の監視のニーズに合わせてエージェントを構成することができます。
注
AgentSettings DCR を使用する際の重要な考慮事項:
- 現在、AgentSettings DCR は、Azure Resource Manager テンプレートを使用してのみ構成できます。
- AgentSettings は、他の設定を含まない単一の DCR である必要があります。
- 仮想マシンと AgentSettings DCR は同じリージョンに配置する必要があります。
 
サポートされているパラメーター
AgentSettings DCR は現在、次のパラメータの設定をサポートしています。
| パラメーター | 説明 | 有効な値 | 
| MaxDiskQuotaInMB | 回復性を提供するために、エージェントは、データを送信できないときにデータを収集してローカル キャッシュ内に保存します。 接続が復元された後、エージェントはキャッシュ内のデータを送信します。 このパラメーターは、Azure Monitor エージェントのログ ファイルとキャッシュによって使われるディスク領域の量 (MB 単位) を定義します。 | Linux: 4,000から1,000,000 default: 10,000へWindows:
 4,000から1,000,000へ | 
| UseTimeReceivedForForwardedEvents | Microsoft Sentinel Windows イベント転送 (WEF) テーブルのWEF列を、 TimeReceivedのデータの代わりにTimeGeneratedを使用するように変更します。 | 0または1 | 
AgentSettings DCR を設定する
- VM に Azure Monitor エージェントをインストール して、環境を準備します。 
- DCR を作成する。 - この例では、Azure Monitor エージェントのキャッシュで使用される最大ディスク容量を 5,000 MB に設定します。 - {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [
    {
    "type": "Microsoft.Insights/dataCollectionRules",
    "name": "dcr-contoso-01",
    "apiVersion": "2023-03-11",
    "properties": 
        {
        "description": "A simple agent settings",
        "agentSettings": 
            {
            "logs": [
                {
                "name": "MaxDiskQuotaInMB",
                "value": "5000"
                }
            ]
            }
        },
    "kind": "AgentSettings",
    "___location": "eastus"
    }
]
}
 
- DCR をマシンに関連付けます。 次の Resource Manager ファイルを使用します。 - テンプレート ファイル: - {
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "metadata": {
        "description": "The name of the virtual machine."
      }
    },
    "dataCollectionRuleId": {
      "type": "string",
      "metadata": {
        "description": "The resource ID of the data collection rule."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Insights/dataCollectionRuleAssociations",
      "apiVersion": "2021-09-01-preview",
      "scope": "[format('Microsoft.Compute/virtualMachines/{0}', parameters('vmName'))]",
      "name": "agentSettings",
      "properties": {
        "description": "Association of data collection rule. Deleting this association will break the data collection for this virtual machine.",
        "dataCollectionRuleId": "[parameters('dataCollectionRuleId')]"
      }
    }
  ]
}
 - パラメーター ファイル: - {
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-azure-vm"
    },
    "dataCollectionRuleId": {
      "value": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/my-resource-group/providers/microsoft.insights/datacollectionrules/my-dcr"
    }
   }
}
 
- 変更を適用するには、Azure Monitor エージェントを再起動します。 
 
関連するコンテンツ
エージェントからデータを収集して Azure Monitor に送信するデータ収集ルールを作成します。