Beispiele für Resource Manager-Vorlagen für VM Insights
Dieser Artikel enthält Beispiele für Azure Resource Manager-Vorlagen zum Aktivieren von VM Insights auf virtuellen Computern. Jedes Beispiel umfasst eine Vorlagendatei und eine Parameterdatei mit Beispielwerten für die Vorlage.
Hinweis
Eine Liste mit verfügbaren Beispielen und Anleitungen zu deren Bereitstellung in Ihrem Azure-Abonnement finden Sie unter Beispiele für Resource Manager-Vorlagen für Azure Monitor.
Konfigurieren des Arbeitsbereichs
Im folgenden Beispiel wird VM Insights für einen Log Analytics-Arbeitsbereich aktiviert.
Vorlagendatei
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'
}
}
Parameterdatei
{
"$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"
}
}
}
Integrieren eines virtuellen Azure-Computers
Im folgenden Beispiel wird ein virtueller Azure-Computer zu VM Insights hinzugefügt
Vorlagendatei
@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
}
}
}
Parameterdatei
{
"$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"
}
}
}
Integrieren einer Azure-VM-Skalierungsgruppe
Im folgenden Beispiel wird VM Insights eine Azure-VM-Skalierungsgruppe hinzugefügt.
Vorlagendatei
@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
}
}
}
Parameterdatei
{
"$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"
}
}
}