你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Log Analytics 工作区中设置一个包含辅助方案的表。

使用辅助表计划,你可以在 Log Analytics 工作区中以低成本方式引入和保留数据。

下方的视频介绍了辅助表计划的一些用途和好处:

Azure Monitor 日志目前支持针对基于数据收集规则 (DCR) 的自定义表的辅助表计划,你可以将通过 Azure Monitor 代理日志引入 API 收集的数据发送到这些表。

本文介绍如何在 Log Analytics 工作区中使用辅助计划创建新的自定义表,并设置将数据发送到此表的数据收集规则。 有关辅助计划概念的详细信息,请参阅 Azure Monitor 日志表计划

先决条件

若要创建自定义表并收集日志数据,你需要以下项:

  • Log Analytics 工作区,你在其中至少拥有参与者权限
  • 数据收集终结点 (DCE)
  • 只有在新建表格时,才能使用辅助计划进行设置。 使用辅助计划创建表后,将无法更改该表的计划。

注释

辅助日志(GA 状态)在除卡塔尔中部以外的所有公共云区域均可用,但在 Azure 政府云和中国云环境中不提供该功能。

创建使用辅助计划的自定义表

若要在 Azure 门户中使用辅助计划创建自定义表,请执行以下操作:

  1. 从“Log Analytics 工作区”菜单中,选择“表格”。

  2. 选择 创建

  3. “基本信息 ”选项卡上,指定名称和(可选)表的说明。 门户会自动将 _CL 后缀添加到表名。

  4. 表计划 下,选择 辅助/湖泊

  5. 选择 “下一步 ”并完成其余步骤以配置架构和数据收集。 有关剩余步骤的详细说明,请参阅 Azure Monitor 日志中的添加或删除表和列

将数据发送到使用辅助计划的表

可以有多种方法使用 Auxiliary 计划将数据导入至自定义表。

  • Azure Monitor 代理 (AMA)
  • 日志引入 API
  • 工作区转换

使用 AMA

如果使用此方法,您的自定义表必须只有两列——TimeGenerated(类型为datetime)和RawData(类型为string)。 数据收集规则会将收集的每个日志条目的全部内容发送到 RawData 列,Azure Monitor 日志会自动使用日志引入时间填充 TimeGenerated 列。

有关如何使用 AMA 的详细信息,请参阅以下文章:

使用日志引入 API

此方法紧随教程中所述的步骤 :使用日志引入 API 将数据发送到 Azure Monitor

  1. 创建使用辅助计划的自定义表,如本文所述。

  2. 创建 Microsoft Entra 应用程序

  3. 创建数据收集规则。 下面是一个适用于 kindDirect的示例 ARM 模板。 此类 DCR 不需要 DCE,因为它包含 logsIngestion 终结点。

    • myworkspace 是 Log Analytics 工作区的名称。
    • tablename_CL 是表的名称。
    • columns 包括在创建表时设置的相同列。
    {
        "$schema": "https://schema.management.azure.com/schemas/2019-08-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 region in which to create the data collection rule. The must be the same region as the destination Log Analytics workspace."}
            },
            "workspaceResourceId": {
                "type": "string",
                "metadata": {"description": "The Azure resource ID of the Log Analytics workspace in which you created a custom table with the Auxiliary plan."}
            }
        },
        "resources": [
            {
                "type": "Microsoft.Insights/dataCollectionRules",
                "name": "[parameters('dataCollectionRuleName')]",
                "location": "[parameters('location')]",
                "apiVersion": "2023-03-11",
                "kind": "Direct",
                "properties": {
                    "streamDeclarations": {
                        "Custom-tablename": {
                            "columns": [
                                {"name": "TimeGenerated",
                                    "type": "datetime"},
                                {"name": "StringProperty",
                                    "type": "string"},
                                {"name": "IntProperty",
                                    "type": "int"},
                                {"name": "LongProperty",
                                    "type": "long"},
                                {"name": "RealProperty",
                                    "type": "real"},
                                {"name": "BooleanProperty",
                                    "type": "boolean"},
                                {"name": "GuidProperty",
                                    "type": "guid"},
                                {"name": "DateTimeProperty",
                                    "type": "datetime"}]
                                    }
                                },
                    "destinations": {
                        "logAnalytics": [
                            {"workspaceResourceId": "[parameters('workspaceResourceId')]",
                                "name": "myworkspace"}]
                    },
                    "dataFlows": [
                        {
                            "streams": ["Custom-tablename"],
                            "transformKql": "source",
                            "destinations": ["myworkspace"],
                            "outputStream": "Custom-tablename_CL"
                        }]
                }
            }],
        "outputs": {
            "dataCollectionRuleId": {
                "type": "string",
                "value": "[resourceId('Microsoft.Insights/dataCollectionRules', parameters('dataCollectionRuleName'))]"
            }
        }
    }
    
  4. 授予应用程序使用 DCR 的权限

  5. 使用 示例代码发送数据。

警告

将日志引入 Azure Monitor 的辅助层时,请避免在一次 API 调用中提交包含跨越超过 30 分钟的 TimeGenerated 时间戳的单个有效负载。 此 API 调用可能会导致以下引入错误代码 RecordsTimeRangeIsMoreThan30Minutes。 这是一个正在被删除的已知限制

此限制不适用于使用 转换的辅助日志。

使用工作区变换

如需了解更多信息,请参阅以下文章: