你当前正在访问 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 政府云和中国云环境中不提供该功能。

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

若要创建自定义表,请使用以下命令调用 表 - 创建 API

PUT https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.OperationalInsights/workspaces/{workspace_name}/tables/{table name_CL}?api-version=2023-01-01-preview

注释

仅 API 版本 2023-01-01-preview 允许设置辅助表计划。

将此有效负载作为请求的正文提供。 更新表名称,并根据表架构调整列。 此示例列出了所有支持的列数据类型。

 {
    "properties": {
        "schema": {
            "name": "table_name_CL",
            "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"}
            ]
        },
        "totalRetentionInDays": 365,
        "plan": "Auxiliary"
    }
}

注释

  • TimeGenerated 列仅支持具有 6 个小数位数的 ISO 8601 格式(纳秒)。 有关详细信息,请参阅 支持的 ISO 8601 日期/时间格式
  • 使用辅助计划的表格不支持包含动态数据的列。

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

目前有两种方法可以通过辅助计划将数据导入到自定义表中。

  • 使用 Azure Monitor Agent (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_CL": {
                              "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-table_name"],
                              "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。 这是一个正在被删除的已知限制

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