閱讀英文

共用方式為

将虚拟机客户端数据发送到事件中心和存储(预览版)

使用 Azure Monitor 从虚拟机客户端收集数据 介绍了如何使用 Azure Monitor 从虚拟机(VM)收集数据。 本文介绍如何将描述的数据发送到 Azure 存储和事件中心。 此功能目前处于公开预览状态。

提示

作为存储的替代方法,应在 Log Analytics 工作区中创建具有 辅助计划的 表,以便进行经济高效的日志记录。

下表列出了此功能支持的数据源。

支持的数据类型

此功能支持下表中的数据类型。 每个文章都有一个链接,其中描述了该源的详细信息。

数据源 操作系统 支持的目的地
Windows 事件日志 Windows操作系统 Eventhub
储存
Syslog Linux Eventhub
储存
性能计数器 Windows操作系统
Linux
Eventhub
储存
IIS 日志 Windows操作系统
Linux
存储 Blob
文本日志 Windows操作系统
Linux
存储 Blob

不支持以下日志:

  • ETW 日志。 该功能计划在后续版本中发布。
  • Windows 故障转储。 Azure Monitoring 代理适用于遥测日志,而不是大型文件类型。
  • 应用程序日志。 这些内容由 Application Insights 收集,后者不使用 DCR。
  • .NET 事件源日志

注意

此功能仅适用于 Azure VM。 不支持已启用 Arc 的 VM。

权限

代理 VM 必须启用系统分配的托管标识或与之关联的用户分配的托管标识。 建议使用用户分配的托管标识来提高可伸缩性和性能。 代理必须配置为使用托管标识进行身份验证,如 Azure Monitor 代理要求中所述。

必须根据所使用的数据目标,将以下 RBAC 角色分配给托管标识。

目的地 RBAC 角色
存储表 Storage Table Data Contributor
存储 blob Storage Blob Data Contributor
事件中心 Azure Event Hubs Data Sender

创建数据收集规则

目前没有用于创建将数据发送到事件中心或存储的数据收集规则(DCR)的 UI 体验。 以下过程介绍了在 Azure 门户中使用 ARM 模板创建 DCR 的步骤。 或者,可以使用此处的示例 DCR ,使用任何其他方法创建新的 DCR

警告

请勿编辑使用 Azure Monitor 从虚拟机客户端收集数据 创建的现有 DCR,以添加事件中心或存储。 这些目标需要使用 DCR,且其 kind 必须为 AgentDirectToStore。 而是使用相同的数据源创建多个 DCR,并将其发送到不同的目的地。

  1. 在 Azure 门户的搜索框中,输入“模板”,然后选择“部署自定义模板”。 选择“在编辑器中生成自己的模板”。

    屏幕截图显示 Azure 门户,其中在搜索框中输入了模板,并在搜索结果中突出显示了“部署自定义模板”。

  2. 将以下模板定义粘贴到编辑器中:

    { 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
        "location": { 
        "type": "string", 
        "defaultValue": "[resourceGroup().location]", 
        "metadata": { 
            "description": "Location for all resources." 
        } 
        }, 
        "dataCollectionRulesName": { 
        "defaultValue": "[concat(resourceGroup().name, 'DCR')]", 
        "type": "String" 
        }, 
        "storageAccountName": { 
        "defaultValue": "[concat(resourceGroup().name, 'sa')]", 
        "type": "String" 
        }, 
        "eventHubNamespaceName": { 
        "defaultValue": "[concat(resourceGroup().name, 'eh')]", 
        "type": "String" 
        }, 
        "eventHubInstanceName": { 
        "defaultValue": "[concat(resourceGroup().name, 'ehins')]", 
        "type": "String" 
        } 
    }, 
    "resources": [ 
        { 
        "type": "Microsoft.Insights/dataCollectionRules", 
        "apiVersion": "2022-06-01", 
        "name": "[parameters('dataCollectionRulesName')]", 
        "location": "[parameters('location')]", 
        "kind": "AgentDirectToStore", 
        "properties": { 
            "dataSources": { 
            "performanceCounters": [ 
                { 
                "streams": [ 
                    "Microsoft-Perf" 
                ], 
                "samplingFrequencyInSeconds": 10, 
                "counterSpecifiers": [ 
                    "Processor(*)\\% Processor Time",
                    "Processor(*)\\% Idle Time",
                    "Processor(*)\\% User Time",
                    "Processor(*)\\% Nice Time",
                    "Processor(*)\\% Privileged Time",
                    "Processor(*)\\% IO Wait Time",
                    "Processor(*)\\% Interrupt Time",
                    "Processor(*)\\% DPC Time",
                    "Memory(*)\\Available MBytes Memory",
                    "Memory(*)\\% Available Memory",
                    "Memory(*)\\Used Memory MBytes",
                    "Memory(*)\\% Used Memory",
                    "Memory(*)\\Pages/sec",
                    "Memory(*)\\Page Reads/sec",
                    "Memory(*)\\Page Writes/sec",
                    "Memory(*)\\Available MBytes Swap",
                    "Memory(*)\\% Available Swap Space",
                    "Memory(*)\\Used MBytes Swap Space",
                    "Memory(*)\\% Used Swap Space",
                    "Logical Disk(*)\\% Free Inodes",
                    "Logical Disk(*)\\% Used Inodes",
                    "Logical Disk(*)\\Free Megabytes",
                    "Logical Disk(*)\\% Free Space",
                    "Logical Disk(*)\\% Used Space",
                    "Logical Disk(*)\\Logical Disk Bytes/sec",
                    "Logical Disk(*)\\Disk Read Bytes/sec",
                    "Logical Disk(*)\\Disk Write Bytes/sec",
                    "Logical Disk(*)\\Disk Transfers/sec",
                    "Logical Disk(*)\\Disk Reads/sec",
                    "Logical Disk(*)\\Disk Writes/sec",
                    "Network(*)\\Total Bytes Transmitted",
                    "Network(*)\\Total Bytes Received",
                    "Network(*)\\Total Bytes",
                    "Network(*)\\Total Packets Transmitted",
                    "Network(*)\\Total Packets Received",
                    "Network(*)\\Total Rx Errors",
                    "Network(*)\\Total Tx Errors",
                    "Network(*)\\Total Collisions"
                ], 
                "name": "perfCounterDataSource10" 
                } 
            ], 
            "syslog": [ 
                { 
                "streams": [ 
                    "Microsoft-Syslog" 
                ], 
                "facilityNames": [
                                    "auth",
                                    "authpriv",
                                    "cron",
                                    "daemon",
                                    "mark",
                                    "kern",
                                    "local0",
                                    "local1",
                                    "local2",
                                    "local3",
                                    "local4",
                                    "local5",
                                    "local6",
                                    "local7",
                                    "lpr",
                                    "mail",
                                    "news",
                                    "syslog",
                                    "user",
                                    "uucp"
                                ],
                "logLevels": [
                                    "Debug",
                                    "Info",
                                    "Notice",
                                    "Warning",
                                    "Error",
                                    "Critical",
                                    "Alert",
                                    "Emergency"
                                ], 
                "name": "syslogDataSource" 
                } 
            ], 
            "logFiles": [ 
                { 
                "streams": [ 
                    "Custom-Text-logs" 
                ], 
                "filePatterns": [ 
                    "/var/log/messages" 
                ], 
                "format": "text", 
                "settings": { 
                    "text": { 
                    "recordStartTimestampFormat": "ISO 8601" 
                    } 
                }, 
                "name": "myTextLogs" 
                } 
            ] 
            }, 
            "destinations": { 
                "eventHubsDirect": [ 
                    { 
                    "eventHubResourceId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('eventHubNamespaceName'), parameters('eventHubInstanceName'))]", 
                    "name": "myEh1" 
                    } 
                ], 
                "storageBlobsDirect": [ 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "blobNamedPerf", 
                    "containerName": "PerfBlob" 
                    }, 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "blobNamedLinux", 
                    "containerName": "SyslogBlob" 
                    }, 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "blobNamedTextLogs", 
                    "containerName": "TxtLogBlob" 
                    } 
                ], 
                "storageTablesDirect": [ 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "tableNamedPerf", 
                    "tableName": "PerfTable" 
                    }, 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "tableNamedLinux", 
                    "tableName": "LinuxTable" 
                    }, 
                    { 
                    "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]", 
                    "name": "tableUnnamed" 
                    } 
                ] 
            }, 
            "dataFlows": [ 
            { 
                "streams": [ 
                "Microsoft-Perf" 
                ], 
                "destinations": [ 
                "myEh1", 
                "blobNamedPerf", 
                "tableNamedPerf", 
                "tableUnnamed" 
                ] 
            }, 
            { 
                "streams": [ 
                "Microsoft-Syslog" 
                ], 
                "destinations": [ 
                "myEh1", 
                "blobNamedLinux", 
                "tableNamedLinux", 
                "tableUnnamed" 
                ] 
            }, 
            { 
                "streams": [ 
                "Custom-Text-logs" 
                ], 
                "destinations": [ 
                "blobNamedTextLogs" 
                ] 
            } 
            ] 
        } 
        } 
    ] 
    }
    
  3. 使用下表中 DCR 部分的详细信息,根据要求编辑模板。 模板使用参数来接受存储帐户和事件中心的名称,以便在保存模板或参数文件中时提供这些名称,具体取决于部署模板的方式。 有关 DCR 结构的更多详细信息 ,请参阅 Azure Monitor 中的数据收集规则的结构(DCR )。

    价值 DESCRIPTION
    dataSources 每个由 DCR 收集的数据源的条目。 示例模板包括日志和性能计数器的定义。 有关配置这些数据源以及可添加到模板的其他数据源的详细信息 ,请参阅 Azure Monitor 中的数据收集规则(DCR)示例
    destinations 每个目标一个条目。

    事件中心
    使用 eventHubsDirect 直接上传到事件中心。 eventHubResourceId 包括事件中心实例的资源 ID。

    存储 Blob
    使用 storageBlobsDirect 直接上传到 blob 存储。 storageAccountResourceId 包括存储帐户的资源 ID。 containerName 包括容器的名称。

    存储表
    使用 storageTablesDirect 直接上传到表存储。 storageAccountResourceId 包括存储帐户的资源 ID。 tableName 包括表的可选名称。
    dataFlows 一个 dataflow ,用于将每个传入流匹配到至少一个目标。 来自该源的数据将发送到数据流中的每个目标。
  4. 选择 “保存” 并为所需的参数提供值。

创建 DCR 关联并部署 Azure Monitor 代理

要使用 DCR,它必须与一个或多个安装了 Azure Monitor 代理(AMA)的虚拟机建立数据收集规则关联(DCRA)。 要了解安装代理的不同选项,请参阅 安装和管理 Azure Monitor 代理;要了解创建 DCRA 的不同选项,请参阅 在 Azure Monitor 中管理数据收集规则关联

以下 ARM 模板可用于部署 Azure Monitor 代理,为特定 VM 创建 DCRA。 该模板使用用户分配的托管标识(UAI)进行身份验证。 部署模板之前,必须先创建 UAI。 还可以使用系统分配的托管标识,但不建议将其用于生产工作负荷。

使用上述过程或任何其他有效方法部署此模板。 它包含用于标识 VM 和 DCR 所需的值的参数,因此无需修改模板本身。

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "vmName": {
    "defaultValue": "[concat(resourceGroup().name, 'vm')]",
    "type": "String"
    },
    "location": {
    "type": "string",
    "defaultValue": "[resourceGroup().location]",
    "metadata": {
        "description": "Location for all resources."
    }
    },
    "dataCollectionRulesName": {
    "defaultValue": "[concat(resourceGroup().name, 'DCR')]",
    "type": "String",
    "metadata": {
        "description": "Data Collection Rule Name"
    }
    },
    "dcraName": {
    "type": "string",
    "defaultValue": "[concat(uniquestring(resourceGroup().id), 'DCRLink')]",
    "metadata": {
        "description": "Name of the association."
    }
    },
    "identityName": {
    "type": "string",
    "defaultValue": "[concat(resourceGroup().name, 'UAI')]",
    "metadata": {
        "description": "Managed Identity"
    }
    }
},
"resources": [
    {
    "type": "Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations",
    "name": "[concat(parameters('vmName'),'/microsoft.insights/', parameters('dcraName'))]",
    "apiVersion": "2021-04-01",
    "properties": {
        "description": "Association of data collection rule. Deleting this association will break the data collection for this virtual machine.",
        "dataCollectionRuleId": "[resourceID('Microsoft.Insights/dataCollectionRules',parameters('dataCollectionRulesName'))]"
    }
    },
    {
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(parameters('vmName'), '/AMAExtension')]",
    "apiVersion": "2020-06-01",
    "location": "[parameters('location')]",
    "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations', parameters('vmName'), 'Microsoft.Insights', parameters('dcraName'))]"
    ],
    "properties": {
        "publisher": "Microsoft.Azure.Monitor",
        "type": "AzureMonitorWindowsAgent",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
        "authentication": {
            "managedIdentity": {
            "identifier-name": "mi_res_id",
            "identifier-value": "[resourceID('Microsoft.ManagedIdentity/userAssignedIdentities/',parameters('identityName'))]"
            }
        }
        }
    }
    }
]
}

从适用于 Linux 和 Windows 的 Azure 诊断扩展 (LAD/WAD) 迁移

Azure 诊断扩展 当前将数据发送到事件中心和存储,但将于 2026 年 3 月 31 日弃用。 在此日期之后,Microsoft 将不再为 Azure 诊断扩展提供支持。 仅提供安全修补程序。 Azure Monitor 代理(AMA)提供了一种更高效、更灵活的方法,用于从 VM 收集客户端数据。

  • 若要检查 VM 上安装了哪些扩展,请选择 VM 上“设置”下的“扩展 + 应用程序”
  • 在设置 Azure Monitor 代理以将相同的数据收集到事件中心或 Azure 存储后,请删除 LAD 或 WAD,以避免数据重复。

故障排除

如果未将数据发送到事件中心或存储,请检查以下内容:

  • 在存储帐户或事件中心中,权限中列出的相应内置角色被分配了托管标识。
  • 已将托管标识分配给 VM。
  • AMA 设置具有托管标识参数。

另请参阅