輔助資料表方案可讓您以低成本的方式在 Log Analytics 工作區中擷取和保留資料。
以下影片說明輔助資料表方案的一些用途和優點:
Azure 監視器記錄目前只會在以資料收集規則 (DCR) 為基礎的自訂資料表上支援輔助資料表方案,而您會將使用 Azure 監視器代理程式或記錄擷取 API所收集到的資料傳送至這些自訂資料表。
本文說明如何在 Log Analytics 工作區中使用輔助計劃建立新的自定義數據表,並設定將數據傳送至此數據表的數據收集規則。 如需輔助方案概念的詳細資訊,請參閱 Azure 監視器記錄數據表計劃。
先決條件
若要建立自訂資料表並收集記錄資料,您需要:
- 您至少擁有 Log Analytics 工作區的參與者權限。
- 資料收集端點 (DCE)。
- 設定使用輔助方案的資料表僅在新的資料表上受支援。 使用輔助方案建立資料表之後,就無法切換資料表的方案。
備註
輔助記錄在卡達中部以外的所有公用雲端區域都已正式發行 (GA),但不適用於 Azure Government 雲端或中國雲端。
建立使用輔助方案的自訂資料表
若要建立自訂資料表,請使用此命令呼叫 資料表 - 建立 API :
PUT https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.OperationalInsights/workspaces/{workspace_name}/tables/{table name_CL}?api-version={api-version}
提供此承載作為您的要求的本文。 更新數據表名稱,並根據數據表架構調整數據行。 此範例會列出所有支持的數據行數據類型。
{
"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 監視器代理程式 (AMA)
- 日誌匯入 API
- 工作區轉換
使用 AMA
如果您使用此方法,您的自訂表格必須只有兩欄 - TimeGenerated (類型 datetime) 和 RawData (類型 string)。 資料收集規則會將您收集的每個記錄項目完整傳送至 RawData 資料行,而 Azure 監視器記錄會自動在 TimeGenerated 資料行內填入記錄的擷取時間。
如需如何使用 AMA 的詳細資訊,請參閱下列文章:
使用記錄匯入 API
此方法會嚴格遵循 教學課程:使用記錄擷取 API 將資料傳送至 Azure 監視器中所述的步驟。
- 建立使用輔助方案的自訂資料表,如本文所述。
- 建立 Microsoft Entra 應用程式。
-
建立資料收集規則。 以下是 ARM 範本
kind範例:Direct。 這種類型的 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'))]" } } }
- 授與您的應用程式使用 DCR 的權限。
- 使用 範例程式碼傳送資料。
警告
在將記錄內嵌到 Azure 監視器的輔助服務層級時,請避免在一個 API 呼叫中提交包含跨時超過 30 分鐘之 TimeGenerated 時間戳記的單一承載。 此 API 呼叫可能會導致下列擷取錯誤碼 RecordsTimeRangeIsMoreThan30Minutes。 這是一個 已知的限制 ,即將被刪除。
此限制不適用於使用 轉換的輔助日誌。
使用工作區變換
如需詳細資訊,請參閱下列文章: