Share via


將 Azure 資料總管和 Azure Resource Graph 中的資料與 Log Analytics 工作區中的資料相互關聯

您可以將 Azure 資料總管Azure Resource Graph 中的資料與 Log Analytics 工作區和 Application Insights 資源中的資料相互關聯,以增強您在 Azure 監視器記錄中的分析。 Microsoft Sentinel 也會將資料儲存在 Log Analytics 工作區中,可支援對 Azure 資料總管的跨服務查詢,但對 Azure Resource Graph 則不支援。 本文說明如何從任何將資料儲存在 Log Analytics 工作區中的服務執行跨服務查詢。

使用任何支援 Kusto 查詢語言 (KQL) 查詢的用戶端工具來執行跨服務查詢,包括 Log Analytics Web UI、活頁簿、PowerShell 和 REST API。

需要的權限

若要執行跨服務查詢,以將 Azure 數據總管或 Azure Resource Graph 中的數據與 Log Analytics 工作區中的數據相互關聯,您需要:

  • 對您查詢的 Log Analytics 工作區擁有 Microsoft.OperationalInsights/workspaces/query/*/read 權限,如 Log Analytics 讀者內建角色所提供。
  • 您在 Azure Resource Graph 中查詢之資源的讀者權限。
  • 您在 Azure 資料總管中查詢之資料表的檢視者權限。

使用 adx() 在 Azure 資料總管中查詢資料

adx 模式內的查詢中輸入 Azure 資料總管叢集的識別碼,後面接著資料庫名稱和資料表。

adx('https://help.kusto.windows.net/Samples').StormEvents

結合 Azure 資料總管叢集資料表與 Log Analytics 工作區

使用 union 命令將叢集資料表與 Log Analytics 工作區結合。

例如:

union customEvents, adx('https://help.kusto.windows.net/Samples').StormEvents
| take 10
let CL1 = adx('https://help.kusto.windows.net/Samples').StormEvents;
union customEvents, CL1 | take 10

提示

允許簡短格式:ClusterName/InitialCatalog。 例如,adx('help/Samples') 會轉譯為 adx('help.kusto.windows.net/Samples')

使用 join 運算子 (而非聯集) 時,您必須使用 hint 來結合 Azure 資料總管叢集中的資料與 Log Analytics 工作區。 使用 Hint.remote={Direction of the Log Analytics Workspace}

例如:

AzureDiagnostics
| join hint.remote=left adx("cluster=ClusterURI").AzureDiagnostics on (ColumnName)

將一個租用戶中的 Azure 資料總管叢集資料與另一個租用戶中的 Azure 監視器資源資料聯結

不支援在服務之間進行跨租用戶查詢。 您會登入單一租用戶來執行橫跨這兩個資源的查詢。

如果 Azure 資料總管資源是在租用戶 A 中,而 Log Analytics 工作區是在租用戶 B 中,請使用下列其中一種方法:

  • 使用 Azure 資料總管,為不同租用戶中的主體新增角色。 將租用戶「B」中的使用者識別碼新增為 Azure 資料總管叢集上的授權使用者。 驗證 Azure 資料總管叢集上的 TrustedExternalTenant 屬性是否包含租用戶 B。在租用戶 B 中完整執行交叉查詢。
  • 使用 Lighthouse 將 Azure 監視器資源投射到租用戶 A。

從不同的租用戶連線到 Azure 資料總管叢集

Kusto Explorer 會自動將您登入使用者帳戶原先所屬的租用戶。 若要使用相同的使用者帳戶存取其他租用戶中的資源,您必須在連接字串中明確指定 TenantId

Data Source=https://ade.applicationinsights.io/subscriptions/SubscriptionId/resourcegroups/ResourceGroupName;Initial Catalog=NetDefaultDB;AAD Federated Security=True;Authority ID=TenantId

使用 arg() 查詢 Azure Resource Graph 中的資料 (預覽)

輸入 arg("") 模式,後面接著 Azure Resource Graph 資料表名稱。

例如:

arg("").<Azure-Resource-Graph-table-name>

以下是一些使用新的 Azure Resource Graph 跨服務查詢功能的範例 Azure Log Analytics 查詢:

  • 根據 Azure Resource Graph 查詢的結果來篩選 Log Analytics 查詢:

    arg("").Resources 
    | where type == "microsoft.compute/virtualmachines" and properties.hardwareProfile.vmSize startswith "Standard_D"
    | join (
        Heartbeat
        | where TimeGenerated > ago(1d)
        | distinct Computer
        )
        on $left.name == $right.Computer
    
  • 建立只會對取自 ARG 查詢的特定資源套用的警示規則:

    • 根據標籤排除資源 – 例如,不要對具有 "Test" 標籤的 VM 觸發警示。

      arg("").Resources
      | where tags.environment=~'Test'
      | project name 
      
    • 擷取與 CPU 使用率相關的效能資料,並篩選出具有 "prod" 標籤的資源。

      InsightsMetrics
      | where Name == "UtilizationPercentage"
      | lookup (
          arg("").Resources 
          | where type == 'microsoft.compute/virtualmachines' 
          | project _ResourceId=tolower(id), tags
          )
          on _ResourceId
      | where tostring(tags.Env) == "Prod"
      

更多使用案例:

  • 使用標籤來確認 VM 應全天候執行,還是應在夜間關閉。
  • 對任何包含特定核心數目的伺服器顯示警示。

根據 Log Analytics 工作區的跨服務查詢建立警示

若要根據 Log Analytics 工作區的跨服務查詢建立警示規則,請遵循在 [範圍] 索引標籤上,選取 Log Analytics 工作區中的建立或編輯記錄搜尋警示規則中的步驟。

注意

您也可以選取相關資源作為警示範圍,以執行從 Azure 數據總管和 Azure Resource Graph 到 Log Analytics 工作區的跨服務查詢。

限制

一般跨服務查詢限制

  • 跨服務查詢不支援參數化函式,和定義包含其他跨工作區或跨服務運算式 (包括 adx()arg()resource()workspace()app()) 的函式。
  • 跨服務查詢僅支援 ".show" 函式。 這項功能可讓跨叢集查詢直接參考 Azure 監視器、Azure 資料總管或 Azure Resource Graph 表格式函式。 跨服務查詢支援下列命令:
    • .show functions
    • .show function {FunctionName}
    • .show database {DatabaseName} schema as json
  • 資料庫名稱會區分大小寫。
  • 不支援識別叢集中的時間戳記資料行。 Log Analytics 查詢 API 無法通過時間篩選。
  • 跨服務查詢僅支援資料擷取。
  • Private Link (私人端點) 和 IP 限制 不支援跨服務查詢。
  • mv-expand 限制為 2,000 筆記錄。
  • Azure 監視器記錄不支援 函 external_table() 式,可讓您在 Azure 數據總管中查詢外部數據表。 若要查詢外部資料表,請在 Azure 資料總管中將 external_table(<external-table-name>) 定義為無參數函式。 接著,您可以使用運算式 adx("").<function-name> 來呼叫函式。

Azure Resource Graph 跨服務查詢限制

  • Microsoft Sentinel 不支援 Azure Resource Graph 的跨服務查詢。
  • 當您從 Azure 監視器查詢 Azure Resource Graph 資料時:
    • 查詢只會傳回前 1,000 筆記錄。
    • Azure 監視器不會傳回 Azure Resource Graph 查詢錯誤。
    • Log Analytics 查詢編輯器會將有效的 Azure Resource Graph 查詢標示為語法錯誤。
    • 不使用Hint時,不支持聯結。
    • 下列運算子不受支援:smv-apply()rand()arg_max()arg_min()avg()avg_if()countif()sumif()percentile()percentiles()percentilew()percentilesw()stdev()stdevif()stdevp()variance()variancep()varianceif()

結合 Azure Resource Graph 資料表與 Log Analytics 工作區

使用 union 命令將叢集資料表與 Log Analytics 工作區結合。

例如:

union AzureActivity, arg("").Resources
| take 10
let CL1 = arg("").Resources ;
union AzureActivity, CL1 | take 10

使用 join 運算子 (而非聯集) 時,您必須使用 hint 來結合 Azure Resource Graph 中的資料與 Log Analytics 工作區中的資料。 使用 Hint.remote={Direction of the Log Analytics Workspace}。 例如:

Perf | where ObjectName == "Memory" and (CounterName == "Available MBytes Memory")
| extend _ResourceId = replace_string(replace_string(replace_string(_ResourceId, 'microsoft.compute', 'Microsoft.Compute'), 'virtualmachines','virtualMachines'),"resourcegroups","resourceGroups")
| join hint.remote=left (arg("").Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project _ResourceId=id, tags) on _ResourceId | project-away _ResourceId1 | where tostring(tags.env) == "prod"

下一步