使用 Azure 監視器從虛擬機用戶端收集資料 說明如何使用 Azure 監視器從虛擬機 (VM) 收集數據。 本文說明如何將描述的數據傳送至 Azure 記憶體和事件中樞。 這項功能目前處於公開預覽狀態。
小提示
作為存儲的替代方案,您應該在 Log Analytics 工作區中建立具有 輔助計劃 的資料表,以實現具成本效益的日志記錄。
下表列出此功能支持的數據源。
支援的數據類型
這項功能支援下表中的數據類型。 每個都有描述該來源詳細數據的文章連結。
| 數據源 | 作業系統 | 支援的目的地 |
|---|---|---|
| Windows 事件記錄檔 | 窗戶 | Eventhub 儲存體 |
| Syslog | Linux | Eventhub 儲存體 |
| 效能計數器 | 窗戶 Linux |
Eventhub 儲存體 |
| IIS 記錄 | 窗戶 Linux |
儲存體 Blob |
| 文字記錄 | 窗戶 Linux |
Eventhub (僅限 Linux) 儲存體 Blob |
不支援下列記錄:
- ETW 記錄。 這已針對稍後發行進行規劃。
- Windows 損毀傾印。 Azure 監視代理程式適用於遙測記錄,而不是大型檔案類型。
- 應用程式記錄檔。 這些是由 Application Insights 所收集,不會使用 DCR。
- .NET 事件來源記錄
備註
此功能僅支援 Azure VM。 不支援已啟用 Arc 的 VM。
權限
代理程式 VM 必須啟用系統指派的受控識別,或與其相關聯的使用者指派受控識別。 建議使用使用者指派的受控識別,以提升可擴縮性和效能。 代理程式必須設定為使用受控識別進行驗證,如 Azure 監視器代理程式需求中所述。
根據您使用的資料目的地而定,您必須將下列 RBAC 角色指派給受控識別。
| 目的地 | RBAC 角色 |
|---|---|
| 儲存體資料表 | Storage Table Data Contributor |
| 儲存體 Blob | Storage Blob Data Contributor |
| 事件中樞 | Azure Event Hubs Data Sender |
建立資料收集規則
小提示
現在有預覽功能可建立資料收集規則 (DCR),以使用 Azure 入口網站將資料傳送至事件中樞或儲存體。 請參閱 建立資料收集規則。
目前尚無可用於建立將資料傳送至事件中心或存儲的數據收集規則(DCR)的使用者介面體驗。 下列程序說明在 Azure 入口網站中使用 ARM 範本建立 DCR 的步驟。 或者,您可以在這裡使用範例 DCR,然後用任何其他方法來建立新的 DCR。
警告
請勿編輯您使用 Azure Monitor 從虛擬機用戶端收集數據 建立的現有 DCR,以新增事件中樞或儲存體。 這些目的地需要 kind 為 AgentDirectToStore 的 DCR。 相反地,使用傳送至不同目的地的相同數據源來建立多個 DCR。
在 Azure 入口網站的搜尋方塊中鍵入「範本」,然後選取 [Deploy a custom template] \(部署自訂範本\)。 選取 [在編輯器中組建您自己的範本]。
將下列樣本定義貼到編輯器中:
{ "$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" ] } ] } } ] }使用下表中 DCR 區段的詳細數據,根據您的需求編輯範本。 範本會使用參數來接受記憶體帳戶和事件中樞的名稱,因此您可以在儲存範本或根據部署範本的方式,在參數檔案中提供這些參數。 如需 DCR 結構的詳細資訊,請參閱 Azure 監視器中的數據收集規則結構 (DCR )。
價值觀 說明 dataSourcesDCR 所收集之每個資料來源的項目。 範例範本包含記錄和性能計數器的定義。 如需設定這些數據源,以及您可以新增至範本的其他數據源的詳細資訊,請參閱 Azure 監視器中的數據收集規則 (DCR) 範例 。 destinations每個目的地一個項目。
事件中樞
使用eventHubsDirect直接上傳至事件中樞。eventHubResourceId包含事件中樞實例的資源標識碼。
儲存體 Blob
使用storageBlobsDirect直接上傳至 Blob 儲存體。storageAccountResourceId包含記憶體帳戶的資源識別碼。containerName包含容器的名稱。
儲存體資料表
使用storageTablesDirect直接上傳至資料表儲存體。storageAccountResourceId包含記憶體帳戶的資源識別碼。tableName包含數據表的選擇性名稱。dataFlowsdataflow用以比對每個傳入資料流與至少一個目的地。 來自該來源的數據會傳送至數據流中的每個目的地。選取 [儲存 ],並提供必要參數的值。
建立 DCR 關聯並部署 Azure 監視器代理程式
若要使用 DCR,它必須與一或多個已安裝 Azure 監控代理程式(AMA)的虛擬機建立數據收集規則關聯(DCRA)。 如需安裝 和管理 Azure 監視器代理程式 的不同選項,請參閱在 Azure 監視器中安裝代理程式和管理資料收集規則關聯 以取得不同選項以建立 DCRA。
下列 ARM 範本可用來部署 Azure 監視器代理程式,以針對特定 VM 建立 DCRA。 範本會使用使用者指派的受控識別 (UAI) 進行驗證。 部署範本之前,必須先建立UAI。 您也可以使用系統指派的受控識別,但不建議用於生產工作負載。
使用上述程式或任何其他有效的方法來部署此範本。 其中包含識別 VM 和 DCR 的必要值參數,因此您不需要修改範本本身。
{
"$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'))]"
}
}
}
}
}
]
}
從適用於 Linux 和 Windows 的 Azure 診斷延伸模組 (LAD/WAD) 移轉
Azure 診斷延伸模組 目前會將數據傳送至事件中樞和記憶體,但將於 2026 年 3 月 31 日淘汰。 在此日期之後,Microsoft將不再支援 Azure 診斷 延伸模組。 只會提供安全性修補程式。 Azure 監視器代理程式 (AMA) 提供更有效率且彈性的方式,從 VM 收集客戶端數據。
- 若要檢查 VM 上已安裝哪些擴充功能,請選取 VM 上的 [設定] 下的 [擴充功能 + 應用程式]。
- 設定 Azure 監視器代理程式以將相同的數據收集到事件中樞或 Azure 儲存體 以避免重複數據之後,請移除 LAD 或 WAD。
故障排除
如果未將資料傳送至事件中樞或記憶體,請檢查下列各項:
- 已在儲存體帳戶或事件中樞上使用受控識別指派權限中所列的適當內建角色。
- 受管理的身份已指派給虛擬機器。
- AMA 設定具有受控識別參數。
另請參閱
- 如需建立資料收集規則的詳細資訊,請參閱 使用 Azure 監視器代理程式從虛擬機器收集資料。