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

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

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

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

本文介绍如何在 Log Analytics 工作区中使用辅助计划创建新的自定义表,并设置将数据发送到此表的数据收集规则。

先决条件

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

  • 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

注释

目前只有使用 2023-01-01-preview 版 API 才能设置辅助表计划。

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

 {
    "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": "real"
                },
                 {
                    "name": "DateTimeProperty",
                    "type": "datetime"
                }
            ]
        },
        "totalRetentionInDays": 365,
        "plan": "Auxiliary"
    }
}

注释

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

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

目前有两种方法可以将数据引入到使用辅助计划的自定义表:

  • 使用 Azure Monitor 代理从文本文件收集日志 / 使用 Azure Monitor 代理从 JSON 文件收集日志

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

  • 使用日志引入 API 将数据发送到 Azure Monitor。

    若要使用此方法,请执行以下操作:

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

    2. 按照教程:使用日志引入 API 将数据发送到 Azure Monitor 中所述步骤操作,以便:

      1. 创建 Microsoft Entra 应用程序

      2. 使用此 ARM 模板创建数据收集规则

      {
          "$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-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": "real"
                                  },
                                  {
                                      "name": "DateTimeProperty",
                                      "type": "datetime"
                                  }
                                      ]
                                      }
                                  },
                      "destinations": {
                          "logAnalytics": [
                              {
                                  "workspaceResourceId": "[parameters('workspaceResourceId')]",
                                  "name": "myworkspace"
                              }
                          ]
                      },
                      "dataFlows": [
                          {
                              "streams": [
                                  "Custom-table_name_CL"
                              ],
                              "destinations": [
                                  "myworkspace"
                              ]
                          }
                      ]
                  }
              }
          ],
          "outputs": {
              "dataCollectionRuleId": {
                  "type": "string",
                  "value": "[resourceId('Microsoft.Insights/dataCollectionRules', parameters('dataCollectionRuleName'))]"
              }
          }
      }
      

      地点:

    3. 授予应用程序使用 DCR 的权限

    注释

    数据收集规则(可将数据发送到使用辅助计划的表):

    • 只能将数据发送到单个表。
    • 不能包含转换

后续步骤

了解有关以下方面的详细信息: