將資料傳送至事件中樞和儲存體 (預覽)

本文會說明如何使用 Azure 監視器代理程式 (AMA) 將資料上傳至 Azure 儲存體和事件中樞。 此功能為預覽版。

Azure 監視器代理程式是新的合併遙測代理程式,可從虛擬機等 IaaS 資源收集資料。 透過使用此預覽版中的上傳功能,您可以將您傳送至 Log Analytics 工作區的記錄1上傳至事件中樞和儲存體。 這兩個資料目的地都會使用資料收集規則來設定代理程式的收集設定。

注意

Azure 診斷 延伸模組將於 2026 年 3 月 31 日淘汰。 在此日期之後,Microsoft將不再支援 Azure 診斷 擴充功能。

註腳

1: 不支援所有資料類型;具體詳情請參閱 支援的内容

從適用於 Linux 和 Windows 的 Azure 診斷延伸模組移轉 (LAD/WAD)

  • Azure 監視器代理程式可以收集和傳送數據至多個目的地,包括 Log Analytics 工作區、Azure 事件中樞 和 Azure 儲存體。
  • 若要檢查 VM 上已安裝哪些擴充功能,請選取 VM 上的 [設定] 下的 [擴充功能 + 應用程式]。
  • 設定 Azure 監視器代理程式以將相同的數據收集到事件中樞或 Azure 儲存體 以避免重複數據之後,請移除 LAD 或 WAD。
  • 作為記憶體的替代方式,強烈建議您在Log Analytics工作區中使用輔助方案來設定數據表,以取得符合成本效益的記錄。

提供哪些支援

資料類型

  • Windows:

    • Windoes 事件記錄–至 EventHub 和儲存體
    • Perf 計數器–EventHub 和儲存體
    • IIS 記錄–至儲存體 Blob
    • 自訂記錄 - 至儲存體 Blob
  • Linux:

    • Syslog–至 Eventhub 和儲存體
    • Perf 計數器–至 EventHub 和儲存體
    • 自訂記錄/記錄檔–至儲存體

作業系統

  • Windows 和 Linux 上的 Azure 監視代理程式所支援的環境
  • 只有 Azure VM 支援並計劃支援此功能。 沒有任何計劃將此案例帶入內部部署或 Azure Arc 案例。

不支援的內容

資料類型

  • Windows:
    • ETW 記錄 (稍後發行)
    • Windows 損毀傾印 (非計劃亦不會支援)
    • 應用程式記錄檔 (非計劃亦不會支援)
    • .NET 事件來源記錄 (非計劃亦不會支援)

必要條件

與下列資源相關聯的受控識別 (系統或使用者)。 強烈建議使用使用者指派的受控識別,以取得更佳的可擴縮性和效能。

建立資料收集規則

建立資料收集規則,以收集事件並傳送至儲存體和事件中樞。

  1. 在 Azure 入口網站的搜尋方塊中鍵入「範本」,然後選取 [Deploy a custom template] \(部署自訂範本\)

    顯示 Azure 入口網站的螢幕擷取畫面,其中已於搜尋方塊中輸入範本,並在搜尋結果中醒目提示部署自訂範本。

  2. 選取 [在編輯器中組建您自己的範本]

    顯示在編輯器中建置範本的入口網站畫面螢幕擷取畫面。

  3. 將此 Azure Resource Manager 範本貼到編輯器中:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "Location for all resources."
        }
        },
        "dataCollectionRulesName": {
        "defaultValue": "[concat(resourceGroup().name, 'DCR')]",
        "type": "String"
        },
        "storageAccountName": {
        "defaultValue": "[concat(resourceGroup().name, 'sa')]",
        "type": "String"
        },
        "eventHubNamespaceName": {
        "defaultValue": "[concat(resourceGroup().name, 'eh')]",
        "type": "String"
        },
        "eventHubInstanceName": {
        "defaultValue": "[concat(resourceGroup().name, 'ehins')]",
        "type": "String"
        }
    },
    "resources": [
        {
        "type": "Microsoft.Insights/dataCollectionRules",
        "apiVersion": "2022-06-01",
        "name": "[parameters('dataCollectionRulesName')]",
        "location": "[parameters('location')]",
        "kind": "AgentDirectToStore",
        "properties": {
            "dataSources": {
            "performanceCounters": [
                {
                "streams": [
                    "Microsoft-Perf"
                ],
                "samplingFrequencyInSeconds": 10,
                "counterSpecifiers": [
                    "\\Process(_Total)\\Working Set - Private",
                    "\\Memory\\% Committed Bytes In Use",
                    "\\LogicalDisk(_Total)\\% Free Space",
                    "\\Network Interface(*)\\Bytes Total/sec"
                ],
                "name": "perfCounterDataSource10"
                }
            ],
            "windowsEventLogs": [
                {
                "streams": [
                    "Microsoft-Event"
                ],
                "xPathQueries": [
                    "Application!*[System[(Level=2)]]",
                    "System!*[System[(Level=2)]]"
                ],
                "name": "eventLogsDataSource"
                }
            ],
            "iisLogs": [
                {
                "streams": [
                    "Microsoft-W3CIISLog"
                ],
                "logDirectories": [
                    "C:\\inetpub\\logs\\LogFiles\\W3SVC1\\"
                ],
                "name": "myIisLogsDataSource"
                }
            ],
            "logFiles": [
                {
                "streams": [
                    "Custom-Text-logs"
                ],
                "filePatterns": [
                    "C:\\JavaLogs\\*.log"
                ],
                "format": "text",
                "settings": {
                    "text": {
                    "recordStartTimestampFormat": "ISO 8601"
                    }
                },
                "name": "myTextLogs"
                }
            ]
            },
            "destinations": {
            "eventHubsDirect": [
                {
                "eventHubResourceId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('eventHubNamespaceName'), parameters('eventHubInstanceName'))]",
                "name": "myEh1"
                }
            ],
            "storageBlobsDirect": [
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "blobNamedPerf",
                "containerName": "PerfBlob"
                },
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "blobNamedWin",
                "containerName": "WinEventBlob"
                },
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "blobNamedIIS",
                "containerName": "IISBlob"
                },
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "blobNamedTextLogs",
                "containerName": "TxtLogBlob"
                }
            ],
            "storageTablesDirect": [
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "tableNamedPerf",
                "tableName": "PerfTable"
                },
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "tableNamedWin",
                "tableName": "WinTable"
                },
                {
                "storageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "name": "tableUnnamed"
                }
            ]
            },
            "dataFlows": [
            {
                "streams": [
                "Microsoft-Perf"
                ],
                "destinations": [
                "myEh1",
                "blobNamedPerf",
                "tableNamedPerf",
                "tableUnnamed"
                ]
            },
            {
                "streams": [
                "Microsoft-Event"
                ],
                "destinations": [
                "myEh1",
                "blobNamedWin",
                "tableNamedWin",
                "tableUnnamed"
                ]
            },
            {
                "streams": [
                "Microsoft-W3CIISLog"
                ],
                "destinations": [
                "blobNamedIIS"
                ]
            },
            {
                "streams": [
                "Custom-Text-logs"
                ],
                "destinations": [
                "blobNamedTextLogs"
                ]
            }
            ]
        }
        }
    ]
    }
    
  4. 在 Azure Resource Manager 範本中更新下列值。 請參閱範例 Azure Resource Manager 樣本。

    事件中樞

    Description
    dataSources 根據您的需求加以定義。 對於 Windows,直接上傳至事件中樞的支援類型是 performanceCounterswindowsEventLogs,對於 Linux 則是 performanceCounterssyslog
    destinations 使用 eventHubsDirect 直接上傳至事件中樞。
    eventHubResourceId 事件中樞執行個體的資源識別碼。

    注意: 這不是事件中樞命名空間資源識別碼。
    dataFlows 在 [dataFlows] 下,包含目的地名稱。

    儲存體資料表

    Description
    dataSources 根據您的需求加以定義。 對於 Windows,直接上傳至儲存體資料表的支援類型是 performanceCounterswindowsEventLogs,對於 Linux 則是 performanceCounterssyslog
    destinations 使用 storageTablesDirect 直接上傳至資料表儲存體。
    storageAccountResourceId 儲存體帳戶的資源識別碼。
    tableName 上傳事件資料之 JSON Blob 的資料表名稱。
    dataFlows 在 [dataFlows] 下,包含目的地名稱。

    儲存體 Blob

    Description
    dataSources 根據您的需求加以定義。 對於 Windows,直接上傳至儲存體 Blob 的支援類型是 performanceCounterswindowsEventLogsiisLogslogFiles,對於 Linux 則是 performanceCounterssysloglogFiles
    destinations 使用 storageBlobsDirect 直接上傳至 Blob 儲存體。
    storageAccountResourceId 儲存體帳戶的資源識別碼。
    containerName 上傳事件資料之 JSON Blob 的容器名稱。
    dataFlows 在 [dataFlows] 下,包含目的地名稱。
  5. 選取 [儲存]。

建立 DCR 關聯並部署 Azure 監視器代理程式

使用自訂範本部署來建立 DCR 關聯和 AMA 部署。

  1. 在 Azure 入口網站的搜尋方塊中鍵入「範本」,然後選取 [Deploy a custom template] \(部署自訂範本\)

    顯示 Azure 入口網站的螢幕擷取畫面,其中已於搜尋方塊中輸入範本,並在搜尋結果中醒目提示部署自訂範本。

  2. 選取 [在編輯器中組建您自己的範本]

    顯示在編輯器中建置範本的入口網站畫面螢幕擷取畫面。

  3. 將此 Azure Resource Manager 範本貼到編輯。器中。

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
        "defaultValue": "[concat(resourceGroup().name, 'vm')]",
        "type": "String"
        },
        "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "Location for all resources."
        }
        },
        "dataCollectionRulesName": {
        "defaultValue": "[concat(resourceGroup().name, 'DCR')]",
        "type": "String",
        "metadata": {
            "description": "Data Collection Rule Name"
        }
        },
        "dcraName": {
        "type": "string",
        "defaultValue": "[concat(uniquestring(resourceGroup().id), 'DCRLink')]",
        "metadata": {
            "description": "Name of the association."
        }
        },
        "identityName": {
        "type": "string",
        "defaultValue": "[concat(resourceGroup().name, 'UAI')]",
        "metadata": {
            "description": "Managed Identity"
        }
        }
    },
    "resources": [
        {
        "type": "Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations",
        "name": "[concat(parameters('vmName'),'/microsoft.insights/', parameters('dcraName'))]",
        "apiVersion": "2021-04-01",
        "properties": {
            "description": "Association of data collection rule. Deleting this association will break the data collection for this virtual machine.",
            "dataCollectionRuleId": "[resourceID('Microsoft.Insights/dataCollectionRules',parameters('dataCollectionRulesName'))]"
        }
        },
        {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(parameters('vmName'), '/AMAExtension')]",
        "apiVersion": "2020-06-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations', parameters('vmName'), 'Microsoft.Insights', parameters('dcraName'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Monitor",
            "type": "AzureMonitorWindowsAgent",
            "typeHandlerVersion": "1.0",
            "autoUpgradeMinorVersion": true,
            "settings": {
            "authentication": {
                "managedIdentity": {
                "identifier-name": "mi_res_id",
                "identifier-value": "[resourceID('Microsoft.ManagedIdentity/userAssignedIdentities/',parameters('identityName'))]"
                }
            }
            }
        }
        }
    ]
    }
    
  4. 選取 [儲存]。

疑難排解

使用以下章節針對將資料傳送至事件中樞和儲存體進行疑難排解。

在儲存體帳戶 Blob 儲存體中找不到資料

  • 檢查內建角色 Storage Blob Data Contributor 是否已在儲存體帳戶上獲指派受控識別。
  • 檢查 VM 是否獲指派受控識別。
  • 檢查 AMA 設定是否具有受控識別參數。

在儲存體帳戶資料表儲存體中找不到資料

  • 檢查內建角色 Storage Table Data Contributor 是否已在儲存體帳戶上獲指派受控識別。
  • 檢查 VM 是否獲指派受控識別。
  • 檢查 AMA 設定是否具有受控識別參數。

資料無法流向事件中樞

  • 檢查內建角色 Azure Event Hubs Data Sender 是否已在事件中樞執行個體上獲指派受控識別。
  • 檢查 VM 是否獲指派受控識別。
  • 檢查 AMA 設定是否具有受控識別參數。

AMA 和 WAD/LAD 聚合

Azure 監視代理程式是否會支援將資料上傳至 Application Insights?

否,此支援不屬於藍圖的一部分。 Application Insights 現在由 Log Analytics 工作區提供。

Azure 監視代理程式是否會支援 Windows 損毀傾印作為要上傳的資料類型?

否,此支援不屬於藍圖的一部分。 Azure 監視代理程式適用於遙測記錄,而不是大型檔案類型。

這是否表示不再支援/已淘汰 Linux (LAD) 和 Windows (WAD) 診斷延伸模組?

否,當 Azure 正式宣佈淘汰這些代理程式之後,要過三年的時間才不再支援這些代理程式。

如何設定事件中樞和儲存體資料目的地的 AMA

目前的設定體驗是使用 DCR API。

您仍然會積極開發 WAD 和 LAD 嗎?

WAD 和 LAD 未來只會取得安全性/修補檔。 大部分的工程資金都已移至 Azure 監視代理程式。 強烈建議移轉至 Azure 監視代理程式,以受益於其所有强大的功能。

另請參閱