有关在模板中定义 DCR 和关联的信息,请参阅以下参考资料。
使用以下模板,采用“Azure Monitor 中的数据收集规则的结构”和“Azure Monitor 中的示例数据收集规则 (DCR)”中的信息创建 DCR,以定义 dcr-properties
。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataCollectionRuleName": {
"type": "string",
"metadata": {
"description": "Specifies the name of the Data Collection Rule to create."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Specifies the location in which to create the Data Collection Rule."
}
}
},
"resources": [
{
"type": "Microsoft.Insights/dataCollectionRules",
"name": "[parameters('dataCollectionRuleName')]",
"location": "[parameters('location')]",
"apiVersion": "2021-09-01-preview",
"properties": {
"<dcr-properties>"
}
}
]
}
DCR 关联 - Azure VM
下面的示例在 Azure 虚拟机和数据收集规则之间创建关联。
Bicep 模板文件
@description('The name of the virtual machine.')
param vmName string
@description('The name of the association.')
param associationName string
@description('The resource ID of the data collection rule.')
param dataCollectionRuleId string
resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' existing = {
name: vmName
}
resource association 'Microsoft.Insights/dataCollectionRuleAssociations@2021-09-01-preview' = {
name: associationName
scope: vm
properties: {
description: 'Association of data collection rule. Deleting this association will break the data collection for this virtual machine.'
dataCollectionRuleId: dataCollectionRuleId
}
}
ARM 模板文件
{
"$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."
}
},
"associationName": {
"type": "string",
"metadata": {
"description": "The name of the association."
}
},
"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": "[parameters('associationName')]",
"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"
},
"associationName": {
"value": "my-windows-vm-my-dcr"
},
"dataCollectionRuleId": {
"value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/microsoft.insights/datacollectionrules/my-dcr"
}
}
}
DCR 关联 - 已启用 Arc 的服务器
下面的示例在启用了 Azure Arc 的服务器和数据收集规则之间创建关联。
Bicep 模板文件
@description('The name of the virtual machine.')
param vmName string
@description('The name of the association.')
param associationName string
@description('The resource ID of the data collection rule.')
param dataCollectionRuleId string
resource vm 'Microsoft.HybridCompute/machines@2021-11-01' existing = {
name: vmName
}
resource association 'Microsoft.Insights/dataCollectionRuleAssociations@2021-09-01-preview' = {
name: associationName
scope: vm
properties: {
description: 'Association of data collection rule. Deleting this association will break the data collection for this Arc server.'
dataCollectionRuleId: dataCollectionRuleId
}
}
ARM 模板文件
{
"$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."
}
},
"associationName": {
"type": "string",
"metadata": {
"description": "The name of the association."
}
},
"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.HybridCompute/machines/{0}', parameters('vmName'))]",
"name": "[parameters('associationName')]",
"properties": {
"description": "Association of data collection rule. Deleting this association will break the data collection for this Arc server.",
"dataCollectionRuleId": "[parameters('dataCollectionRuleId')]"
}
}
]
}
参数文件
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"value": "my-hybrid-vm"
},
"associationName": {
"value": "my-windows-vm-my-dcr"
},
"dataCollectionRuleId": {
"value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/microsoft.insights/datacollectionrules/my-dcr"
}
}
}