共用方式為


在 Log Analytics 工作區中使用輔助方案設定數據表

輔助資料表方案可讓您以低成本的方式在 Log Analytics 工作區中擷取和保留資料。

以下影片說明輔助資料表方案的一些用途和優點:

Azure 監視器記錄目前只會在以資料收集規則 (DCR) 為基礎的自訂資料表上支援輔助資料表方案,而您會將使用 Azure 監視器代理程式記錄擷取 API所收集到的資料傳送至這些自訂資料表。

本文說明如何在 Log Analytics 工作區中使用輔助計劃建立新的自定義數據表,並設定將數據傳送至此數據表的數據收集規則。 如需輔助方案概念的詳細資訊,請參閱 Azure 監視器記錄數據表計劃

必要條件

若要建立自訂資料表並收集記錄資料,您需要:

  • 您至少擁有 Log Analytics 工作區的參與者權限
  • 資料收集端點 (DCE)
  • 只有新的數據表才支援設定具有輔助方案的數據表。 使用輔助方案建立資料表之後,就無法切換資料表的方案。

備註

輔助日誌在所有公用雲端區域普遍可用,但不適用於 Microsoft 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 欄僅支援 ISO 8601 格式,精確度為 6 個小數位數(奈秒)。 如需詳細資訊,請參閱 支援的 ISO 8601 日期時間格式
  • 具有輔助計劃的資料表不支援具有動態數據的數據列。

將資料傳送至使用輔助方案的資料表

目前有兩種方式可將資料擷取至使用輔助方案的自訂資料表:

  • 使用 Azure 監視器代理程式從文字檔收集記錄 / 使用 Azure 監視器代理程式從 JSON 檔案收集記錄

    如果您使用此方法,您的自訂資料表必須只有兩個資料行 - TimeGeneratedRawData (類型為 string)。 資料收集規則會將您收集的每個記錄項目完整傳送至 RawData 資料行,而 Azure 監視器記錄會自動在 TimeGenerated 資料行內填入記錄的擷取時間。

  • 使用記錄擷取 API 將資料傳送至 Azure 監視器。

    若要使用此方法:

    1. 建立使用輔助方案的自訂資料表,如本文所述。

    2. 遵循教學課程:使用記錄擷取 API 將資料傳送至 Azure 監視器中所述的步驟:

      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": "guid"
                                  },
                                  {
                                      "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 的權限

下一步

深入了解: