Partager via


Exemples de modèles Resource Manager pour VM Insights

Cet article contient des exemples de modèles Azure Resource Manager permettant d’activer VM Insights sur des machines virtuelles. Chaque exemple comprend un fichier de modèle et un fichier de paramètres avec des exemples de valeurs à fournir au modèle.

Notes

Pour obtenir une liste des exemples disponibles et des conseils sur leur déploiement dans votre abonnement Azure, consultez Exemples Azure Resource Manager pour Azure Monitor.

Configurer l’espace de travail

L’exemple suivant active VM Insights pour un espace de travail Log Analytics.

Fichier de modèle

main.bicep

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

@description('Location of the workspace.')
param workspaceLocation string

module VMISolutionDeployment './nested_VMISolutionDeployment.bicep' = {
  name: 'VMISolutionDeployment'
  scope: resourceGroup(split(workspaceResourceId, '/')[2], split(workspaceResourceId, '/')[4])
  params: {
    workspaceLocation: workspaceLocation
    workspaceResourceId: workspaceResourceId
  }
}

nested_VMISolutionDeployment.bicep

@description('Location of the workspace.')
param workspaceLocation string

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

resource solution 'Microsoft.OperationsManagement/solutions@2015-11-01-preview' = {
  location: workspaceLocation
  name: 'VMInsights(${split(workspaceResourceId, '/')[8]})'
  properties: {
    workspaceResourceId: workspaceResourceId
  }
  plan: {
    name: 'VMInsights(${split(workspaceResourceId, '/')[8]})'
    product: 'OMSGallery/VMInsights'
    promotionCode: ''
    publisher: 'Microsoft'
  }
}

Fichier de paramètres

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspaceResourceId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-workspace"
    },
    "workspaceLocation": {
      "value": "eastus"
    }
  }
}

Intégrer une machine virtuelle Azure

L’exemple suivant ajoute une machine virtuelle Azure à VM Insights.

Fichier de modèle

@description('VM Resource ID.')
param VmResourceId string

@description('The Virtual Machine Location.')
param VmLocation string

@description('OS Type, Example: Linux / Windows')
param osType string

@description('Workspace Resource ID.')
param WorkspaceResourceId string

var VmName_var = split(VmResourceId, '/')[8]
var DaExtensionName = ((toLower(osType) == 'windows') ? 'DependencyAgentWindows' : 'DependencyAgentLinux')
var DaExtensionType = ((toLower(osType) == 'windows') ? 'DependencyAgentWindows' : 'DependencyAgentLinux')
var DaExtensionVersion = '9.5'
var MmaExtensionName = ((toLower(osType) == 'windows') ? 'MMAExtension' : 'OMSExtension')
var MmaExtensionType = ((toLower(osType) == 'windows') ? 'MicrosoftMonitoringAgent' : 'OmsAgentForLinux')
var MmaExtensionVersion = ((toLower(osType) == 'windows') ? '1.0' : '1.4')


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

resource daExtension 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: DaExtensionName
  location: VmLocation
  properties: {
    publisher: 'Microsoft.Azure.Monitoring.DependencyAgent'
    type: DaExtensionType
    typeHandlerVersion: DaExtensionVersion
    autoUpgradeMinorVersion: true
  }
}

resource mmaExtension 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = {
  parent: vm
  name: MmaExtensionName
  location: VmLocation
  properties: {
    publisher: 'Microsoft.EnterpriseCloud.Monitoring'
    type: MmaExtensionType
    typeHandlerVersion: MmaExtensionVersion
    autoUpgradeMinorVersion: true
    settings: {
      workspaceId: reference(WorkspaceResourceId, '2021-12-01-preview').customerId
      azureResourceId: VmResourceId
      stopOnMultipleConnections: true
    }
    protectedSettings: {
      workspaceKey: listKeys(WorkspaceResourceId, '2021-12-01-preview').primarySharedKey
    }
  }
}

Fichier de paramètres

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmResourceId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachines/my-linux-vm"
    },
    "vmLocation": {
      "value": "westus"
    },
    "osType": {
      "value": "linux"
    },
    "workspaceResourceId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-workspace"
    }
  }
}

Intégrer un groupe de machines virtuelles identiques Azure

L’exemple suivant ajoute un groupe de machines virtuelles identiques Azure à VM Insights.

Fichier de modèle

@description('VM Resource ID.')
param VmssResourceId string

@description('The Virtual Machine Location.')
param VmssLocation string

@description('OS Type, Example: Linux / Windows')
param osType string

@description('Workspace Resource ID.')
param WorkspaceResourceId string

var VmssName_var = split(VmssResourceId, '/')[8]
var DaExtensionName = ((toLower(osType) == 'windows') ? 'DependencyAgentWindows' : 'DependencyAgentLinux')
var DaExtensionType = ((toLower(osType) == 'windows') ? 'DependencyAgentWindows' : 'DependencyAgentLinux')
var DaExtensionVersion = '9.5'
var MmaExtensionName = ((toLower(osType) == 'windows') ? 'MMAExtension' : 'OMSExtension')
var MmaExtensionType = ((toLower(osType) == 'windows') ? 'MicrosoftMonitoringAgent' : 'OmsAgentForLinux')
var MmaExtensionVersion = ((toLower(osType) == 'windows') ? '1.0' : '1.4')

resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2021-11-01' = {
  name: VmssName_var
  location: VmssLocation
  properties:{}
}

resource daExtension 'Microsoft.Compute/virtualMachineScaleSets/extensions@2018-10-01' = {
  parent: vmss
  name: DaExtensionName
  properties: {
    publisher: 'Microsoft.Azure.Monitoring.DependencyAgent'
    type: DaExtensionType
    typeHandlerVersion: DaExtensionVersion
    autoUpgradeMinorVersion: true
  }
}

resource mmaExtension 'Microsoft.Compute/virtualMachineScaleSets/extensions@2018-10-01' = {
  parent: vmss
  name: MmaExtensionName
  properties: {
    publisher: 'Microsoft.EnterpriseCloud.Monitoring'
    type: MmaExtensionType
    typeHandlerVersion: MmaExtensionVersion
    autoUpgradeMinorVersion: true
    settings: {
      workspaceId: reference(WorkspaceResourceId, '2021-12-01-preview').customerId
      azureResourceId: VmssResourceId
      stopOnMultipleConnections: true
    }
    protectedSettings: {
      workspaceKey: listKeys(WorkspaceResourceId, '2021-12-01-preview').primarySharedKey
    }
  }
}

Fichier de paramètres

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "VmssResourceId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Compute/virtualMachines/my-windows-vmss"
    },
    "VmssLocation": {
      "value": "westus"
    },
    "OsType": {
      "value": "windows"
    },
    "WorkspaceResourceId": {
      "value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-workspace"
    }
  }
}

Étapes suivantes