Azure Monitor의 에이전트에 대한 Resource Manager 템플릿 샘플

이 문서에는 Azure Monitor의 가상 머신에 대한 Azure Monitor 에이전트, 레거시 Log Analytics 에이전트, 진단 확장을 배포 및 구성하는 샘플 Azure Resource Manager 템플릿이 포함되어 있습니다. 각 샘플에는 템플릿 파일과 템플릿에 제공할 샘플 값이 포함된 매개 변수 파일이 포함되어 있습니다.

참고 항목

사용 가능한 샘플 목록과 Azure 구독에 배포하는 방법에 대한 지침은 Azure Monitor에 대한 Azure Resource Manager 샘플을 참조하세요.

Azure Monitor 에이전트

이 섹션의 샘플은 Windows와 Linux 가상 머신 및 Azure Arc 지원 서버에 Azure Monitor 에이전트를 설치합니다.

필수 조건

아래 템플릿을 사용하려면 다음이 필요합니다.

필수 사용 권한

기본 제공 역할 범위 원인
  • 가상 머신, 가상 머신 확장 집합
  • Arc 지원 서버
에이전트 확장을 배포하려면 다음을 수행합니다.
Microsoft.Resources/deployments/* 작업을 포함하는 모든 역할
  • 구독 및/또는
  • 리소스 그룹 및/또는
  • 기존 데이터 컬렉션 규칙
ARM 템플릿을 배포하려면 다음을 수행합니다.

Azure Windows 가상 머신

다음 샘플에서는 Azure Windows 가상 머신에 Azure Monitor 에이전트를 설치합니다. 선택한 인증 방법에 따라 아래의 적절한 템플릿을 사용합니다.

param vmName string
param location string
param userAssignedManagedIdentity string

resource windowsAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  name: '${vmName}/AzureMonitorWindowsAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorWindowsAgent'
    typeHandlerVersion: '1.0'
    autoUpgradeMinorVersion: true
    enableAutomaticUpgrade: true
    settings: {
      authentication: {
        managedIdentity: {
          'identifier-name': 'mi_res_id'
          'identifier-value': userAssignedManagedIdentity
        }
      }
    }
  }
}
매개 변수 파일
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-windows-vm"
    },
    "location": {
      "value": "eastus"
    },
    "userAssignedManagedIdentity": {
      "value": "/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"
    }
  }
}

시스템 할당 관리 ID

템플릿 파일
param vmName string
param location string

resource windowsAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  name: '${vmName}/AzureMonitorWindowsAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorWindowsAgent'
    typeHandlerVersion: '1.0'
    autoUpgradeMinorVersion: true
    enableAutomaticUpgrade: true
  }
}
매개 변수 파일
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-windows-vm"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Azure Linux 가상 머신

다음 샘플에서는 Azure Linux 가상 머신에 Azure Monitor 에이전트를 설치합니다. 선택한 인증 방법에 따라 아래의 적절한 템플릿을 사용합니다.

템플릿 파일
param vmName string
param location string
param userAssignedManagedIdentity string

resource linuxAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  name: '${vmName}/AzureMonitorLinuxAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorLinuxAgent'
    typeHandlerVersion: '1.21'
    autoUpgradeMinorVersion: true
    enableAutomaticUpgrade: true
    settings: {
      authentication: {
        managedIdentity: {
          'identifier-name': 'mi_res_id'
          'identifier-value': userAssignedManagedIdentity
        }
      }
    }
  }
}
매개 변수 파일
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-linux-vm"
    },
    "location": {
      "value": "eastus"
    },
    "userAssignedManagedIdentity": {
      "value": "/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"
    }
  }
}

시스템 할당 관리 ID

템플릿 파일
param vmName string
param location string

resource linuxAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  name: '${vmName}/AzureMonitorLinuxAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorLinuxAgent'
    typeHandlerVersion: '1.21'
    autoUpgradeMinorVersion: true
    enableAutomaticUpgrade: true
  }
}
매개 변수 파일
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-linux-vm"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Azure Arc 지원 Windows 서버

다음 샘플에서는 Azure Arc 지원 Windows 서버에 Azure Monitor 에이전트를 설치합니다.

템플릿 파일

param vmName string
param location string

resource windowsAgent 'Microsoft.HybridCompute/machines/extensions@2021-12-10-preview' = {
  name: '${vmName}/AzureMonitorWindowsAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorWindowsAgent'
    autoUpgradeMinorVersion: true
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "vmName": {
        "value": "my-windows-vm"
      },
      "location": {
        "value": "eastus"
      }
  }
}

Azure Arc 지원 Linux 서버

다음 샘플에서는 Azure Arc 지원 Linux 서버에 Azure Monitor 에이전트를 설치합니다.

템플릿 파일

param vmName string
param location string

resource linuxAgent 'Microsoft.HybridCompute/machines/extensions@2021-12-10-preview'= {
  name: '${vmName}/AzureMonitorLinuxAgent'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Monitor'
    type: 'AzureMonitorLinuxAgent'
    autoUpgradeMinorVersion: true
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-linux-vm"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Log Analytics 에이전트

이 섹션의 샘플은 Azure의 Windows 및 Linux 가상 머신에 레거시 Log Analytics 에이전트를 설치하고 Log Analytics 작업 영역에 연결합니다.

Windows

다음 샘플에서는 Azure 가상 머신에 Log Analytics 에이전트를 설치합니다. 이 작업은 Windows용 Log Analytics 가상 머신 확장을 사용하도록 설정하여 수행합니다.

템플릿 파일

@description('Name of the virtual machine.')
param vmName string

@description('Location of the virtual machine')
param location string = resourceGroup().location

@description('Id of the workspace.')
param workspaceId string

@description('Primary or secondary workspace key.')
param workspaceKey string

resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: vmName
  location: location
  properties:{}
}

resource logAnalyticsAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: 'Microsoft.Insights.LogAnalyticsAgent'
  location: location
  properties: {
    publisher: 'Microsoft.EnterpriseCloud.Monitoring'
    type: 'MicrosoftMonitoringAgent'
    typeHandlerVersion: '1.0'
    autoUpgradeMinorVersion: true
    settings: {
      workspaceId: workspaceId
    }
    protectedSettings: {
      workspaceKey: workspaceKey
    }
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-windows-vm"
    },
    "location": {
      "value": "westus"
    },
    "workspaceId": {
      "value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    },
    "workspaceKey": {
      "value": "Tse-gj9CemT6A80urYa2hwtjvA5axv1xobXgKR17kbVdtacU6cEf+SNo2TdHGVKTsZHZd1W9QKRXfh+$fVY9dA=="
    }
  }
}

Linux

다음 샘플에서는 Linux Azure 가상 머신에 Log Analytics 에이전트를 설치합니다. 이 작업은 Linux용 Log Analytics 가상 머신 확장을 사용하도록 설정하여 수행합니다.

템플릿 파일

@description('Name of the virtual machine.')
param vmName string

@description('Location of the virtual machine')
param location string = resourceGroup().location

@description('Id of the workspace.')
param workspaceId string

@description('Primary or secondary workspace key.')
param workspaceKey string

resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: vmName
  location: location
}

resource logAnalyticsAgent 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: 'Microsoft.Insights.LogAnalyticsAgent'
  location: location
  properties: {
    publisher: 'Microsoft.EnterpriseCloud.Monitoring'
    type: 'OmsAgentForLinux'
    typeHandlerVersion: '1.7'
    autoUpgradeMinorVersion: true
    settings: {
      workspaceId: workspaceId
    }
    protectedSettings: {
      workspaceKey: workspaceKey
    }
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-linux-vm"
    },
    "location": {
      "value": "westus"
    },
    "workspaceId": {
      "value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    },
    "workspaceKey": {
      "value": "Tse-gj9CemT6A80urYa2hwtjvA5axv1xobXgKR17kbVdtacU6cEf+SNo2TdHGVKTsZHZd1W9QKRXfh+$fVY9dA=="
    }
  }
}

진단 확장

이 섹션의 샘플은 Azure의 Windows 및 Linux 가상 머신에 진단 확장을 설치하고 데이터 수집을 위해 구성합니다.

Windows

다음 샘플에서는 Azure 가상 머신에서 진단 확장을 사용하도록 설정하고 구성합니다. 구성에 대한 자세한 내용은 Windows 진단 확장 스키마를 참조하세요.

템플릿 파일

@description('Name of the virtual machine.')
param vmName string

@description('Location for the virtual machine.')
param location string = resourceGroup().location

@description('Name of the storage account.')
param storageAccountName string

@description('Resource ID of the storage account.')
param storageAccountId string

@description('Resource ID of the workspace.')
param workspaceResourceId string

resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: vmName
  location: location
}

resource vmDiagnosticsSettings 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: 'Microsoft.Insights.VMDiagnosticsSettings'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Diagnostics'
    type: 'IaaSDiagnostics'
    typeHandlerVersion: '1.5'
    autoUpgradeMinorVersion: true
    settings: {
      WadCfg: {
        DiagnosticMonitorConfiguration: {
          overallQuotaInMB: 10000
          DiagnosticInfrastructureLogs: {
            scheduledTransferLogLevelFilter: 'Error'
          }
          PerformanceCounters: {
            scheduledTransferPeriod: 'PT1M'
            sinks: 'AzureMonitorSink'
            PerformanceCounterConfiguration: [
              {
                counterSpecifier: '\\Processor(_Total)\\% Processor Time'
                sampleRate: 'PT1M'
                unit: 'percent'
              }
            ]
          }
          WindowsEventLog: {
            scheduledTransferPeriod: 'PT5M'
            DataSource: [
              {
                name: 'System!*[System[Provider[@Name=\'Microsoft Antimalware\']]]'
              }
              {
                name: 'System!*[System[Provider[@Name=\'NTFS\'] and (EventID=55)]]'
              }
              {
                name: 'System!*[System[Provider[@Name=\'disk\'] and (EventID=7 or EventID=52 or EventID=55)]]'
              }
            ]
          }
        }
        SinksConfig: {
          Sink: [
            {
              name: 'AzureMonitorSink'
              AzureMonitor: {
                ResourceId: workspaceResourceId
              }
            }
          ]
        }
      }
      storageAccount: storageAccountName
    }
    protectedSettings: {
      storageAccountName: storageAccountName
      storageAccountKey: listkeys(storageAccountId, '2021-08-01').key1
      storageAccountEndPoint: 'https://${environment().suffixes.storage}'
    }
  }
}

resource managedIdentity 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: 'ManagedIdentityExtensionForWindows'
  location: location
  properties: {
    publisher: 'Microsoft.ManagedIdentity'
    type: 'ManagedIdentityExtensionForWindows'
    typeHandlerVersion: '1.0'
    autoUpgradeMinorVersion: true
    settings: {
      port: 50342
    }
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "vmName": {
        "value": "my-windows-vm"
      },
      "location": {
        "value": "westus"
      },
      "storageAccountName": {
        "value": "mystorageaccount"
      },
      "storageAccountId": {
        "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Storage/storageAccounts/my-windows-vm"
      },
      "workspaceResourceId": {
        "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-workspace"
      }
  }
}

Linux

다음 샘플에서는 Linux Azure 가상 머신에서 진단 확장을 사용하도록 설정하고 구성합니다. 구성에 대한 자세한 내용은 Windows 진단 확장 스키마를 참조하세요.

템플릿 파일

@description('Name of the virtual machine.')
param vmName string

@description('Resource ID of the virtual machine.')
param vmId string

@description('Location for the virtual machine.')
param location string = resourceGroup().location

@description('Name of the storage account.')
param storageAccountName string

@description('Resource ID of the storage account.')
param storageSasToken string

@description('URL of the event hub.')
param eventHubUrl string

resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: vmName
  location: location
}

resource vmDiagnosticsSettings 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: 'Microsoft.Insights.VMDiagnosticsSettings'
  location: location
  properties: {
    publisher: 'Microsoft.Azure.Diagnostics'
    type: 'LinuxDiagnostic'
    typeHandlerVersion: '3.0'
    autoUpgradeMinorVersion: true
    settings: {
      StorageAccount: storageAccountName
      ladCfg: {
        sampleRateInSeconds: 15
        diagnosticMonitorConfiguration: {
          performanceCounters: {
            sinks: 'MyMetricEventHub,MyJsonMetricsBlob'
            performanceCounterConfiguration: [
              {
                unit: 'Percent'
                type: 'builtin'
                counter: 'PercentProcessorTime'
                counterSpecifier: '/builtin/Processor/PercentProcessorTime'
                annotation: [
                  {
                    locale: 'en-us'
                    displayName: 'Aggregate CPU %utilization'
                  }
                ]
                condition: 'IsAggregate=TRUE'
                class: 'Processor'
              }
              {
                unit: 'Bytes'
                type: 'builtin'
                counter: 'UsedSpace'
                counterSpecifier: '/builtin/FileSystem/UsedSpace'
                annotation: [
                  {
                    locale: 'en-us'
                    displayName: 'Used disk space on /'
                  }
                ]
                condition: 'Name="/"'
                class: 'Filesystem'
              }
            ]
          }
          metrics: {
            metricAggregation: [
              {
                scheduledTransferPeriod: 'PT1H'
              }
              {
                scheduledTransferPeriod: 'PT1M'
              }
            ]
            resourceId: vmId
          }
          eventVolume: 'Large'
          syslogEvents: {
            sinks: 'MySyslogJsonBlob,MyLoggingEventHub'
            syslogEventConfiguration: {
              LOG_USER: 'LOG_INFO'
            }
          }
        }
      }
      perfCfg: [
        {
          query: 'SELECT PercentProcessorTime, PercentIdleTime FROM SCX_ProcessorStatisticalInformation WHERE Name=\'_TOTAL\''
          table: 'LinuxCpu'
          frequency: 60
          sinks: 'MyLinuxCpuJsonBlob,MyLinuxCpuEventHub'
        }
      ]
      fileLogs: [
        {
          file: '/var/log/myladtestlog'
          table: 'MyLadTestLog'
          sinks: 'MyFilelogJsonBlob,MyLoggingEventHub'
        }
      ]
    }
    protectedSettings: {
      storageAccountName: 'yourdiagstgacct'
      storageAccountSasToken: storageSasToken
      sinksConfig: {
        sink: [
          {
            name: 'MySyslogJsonBlob'
            type: 'JsonBlob'
          }
          {
            name: 'MyFilelogJsonBlob'
            type: 'JsonBlob'
          }
          {
            name: 'MyLinuxCpuJsonBlob'
            type: 'JsonBlob'
          }
          {
            name: 'MyJsonMetricsBlob'
            type: 'JsonBlob'
          }
          {
            name: 'MyLinuxCpuEventHub'
            type: 'EventHub'
            sasURL: eventHubUrl
          }
          {
            name: 'MyMetricEventHub'
            type: 'EventHub'
            sasURL: eventHubUrl
          }
          {
            name: 'MyLoggingEventHub'
            type: 'EventHub'
            sasURL: eventHubUrl
          }
        ]
      }
    }
  }
}

매개 변수 파일

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "my-linux-vm"
    },
    "vmId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachines/my-linux-vm"
    },
    "location": {
      "value": "westus"
    },
    "storageAccountName": {
      "value": "mystorageaccount"
    },
    "storageSasToken": {
      "value": "?sv=2019-10-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-04-26T23:06:44Z&st=2020-04-26T15:06:44Z&spr=https&sig=1QpoTvrrEW6VN2taweUq1BsaGkhDMnFGTfWakucZl4%3D"
    },
    "eventHubUrl": {
      "value": "https://my-eventhub-namespace.servicebus.windows.net/my-eventhub?sr=my-eventhub-namespace.servicebus.windows.net%2fmy-eventhub&sig=4VEGPTg8jxUAbTcyeF2kwOr8XZdfgTdMWEQWnVaMSqw=&skn=manage"
    }
  }
}

다음 단계