Share via


使用 Azure 資料總管來查詢 Azure 監視器中的資料

Azure 資料總管支援 Azure 資料總管、Application Insights (AI)Log Analytics (LA) 之間的跨服務查詢。 您可以使用 Azure 資料總管查詢工具和跨服務查詢來查詢您的 Log Analytics 或 Application Insights 工作區。 本文說明如何建立跨服務查詢,並將 Log Analytics 或 Application Insights 工作區新增至 Azure Data Explorer Web UI。

Azure 資料總管跨服務查詢流程:

顯示 Azure Data Explorer Proxy 流程的圖表。

將 Log Analytics/Application Insights 工作區新增至 Azure 資料總管用戶端工具

將 Log Analytics 或 Application Insights 工作區新增至 Azure 資料總管用戶端工具,為您的叢集啟用跨服務查詢。

  1. 在連線到 Log Analytics 或 Application Insights 叢集之前,請先確認您的 Azure 資料總管原生叢集 (例如 help 叢集) 已出現在左側功能表上。

    顯示左側功能表的螢幕快照,其中已選取說明叢集作為 Azure Data Explorer 原生叢集。

  2. 在 Azure 資料總管 UI (https://dataexplorer.azure.com/clusters) 中,選取 [新增叢集]。

  3. 在 [ 新增叢集 ] 視窗中,新增 Log Analytics (LA) 或 Application Insights (AI) 叢集的 URL。

    • 針對 Log Analytics (LA) : https://ade.loganalytics.io/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>
    • 針對 Application Insights (AI) : https://ade.applicationinsights.io/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.insights/components/<ai-app-name>

    注意

    指定 https://ade.applicationinsights.io/subscriptions/<subscription-id> 以查看訂用帳戶中的所有資料庫。 此語法也適用於Log Analytics叢集。

  4. 選取 [新增]。

    顯示 [新增叢集] 視窗的螢幕快照。

    注意

    • 下列有不同的端點:
    • Azure Government - adx.monitor.azure.us/
    • Azure 中國 - adx.monitor.azure.cn/
    • 如果您將連線新增至一個以上的 Log Analytics/Application Insights 工作區,請提供不同的名稱給每個工作區。 否則,左窗格中的名稱會全部相同。
  5. 建立連線之後,您的 Log Analytics 或 Application Insights 工作區將會出現在左窗格中,並顯示您的原生 Azure 資料總管叢集。

    顯示 Log Analytics 和 Azure Data Explorer 叢集的螢幕快照。

注意

您從 Azure Data Explorer 對 Azure 監視器中資料執行的查詢受限於跨資源查詢限制

執行查詢

您可以使用支援 Kusto 查詢的用戶端工具來執行查詢,例如:Kusto Explorer、Azure Data Explorer Web UI、Jupyter Kqlmagic、Flow、PowerQuery、PowerShell、Lens、REST API。

注意

跨服務查詢功能僅用於資料擷取。 如需詳細資訊,請參閱函式支援性

秘訣

  • 資料庫應該與跨服務查詢中指定的資源名稱相同。 名稱區分大小寫。
  • 在跨服務查詢中,請確定 Application Insights 應用程式和 Log Analytics 工作區的命名是正確的。
  • 如果名稱包含特殊字元,則會以跨服務查詢中的 URL 編碼來取代。
  • 如果名稱中包含不符合 KQL 識別碼名稱規則的字元,則會以破折號 - 字元來取代。

從 Azure 資料總管用戶端工具直接查詢您的 Log Analytics 或 Application Insights 工作區

您可以從 Azure 資料總管用戶端工具在您的 Log Analytics 或 Application Insights 工作區上執行查詢。

  1. 確認左側窗格中已選取您的工作區。

  2. 執行下列查詢:

Perf | take 10 // Demonstrate cross-service query on the Log Analytics workspace

顯示 [查詢 Log Analytics] 工作區的螢幕快照。

跨查詢 Log Analytics 或 Application Insights 工作區和 Azure 資料總管原生叢集

當您執行跨叢集服務查詢時,請確認左側窗格中已選取您的 Azure 資料總管原生叢集。 下列範例會示範如何將 Azure 資料總管叢集資料表 (使用 union) 與 Log Analytics 工作區結合。

執行下列查詢:

union StormEvents, cluster('https://ade.loganalytics.io/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>').database('<workspace-name>').Perf
| take 10
let CL1 = 'https://ade.loganalytics.io/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>';
union <ADX table>, cluster(CL1).database(<workspace-name>).<table name>

顯示來自 Azure Data Explorer Web U I 之跨服務查詢的螢幕快照。

秘訣

若使用 join 運算子 (而不是 union),可能需要 hint 在 Azure 資料總管原生叢集上執行該運算子。

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

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

如果 Azure Data Explorer 資源位於租使用者 'A',而 Log Analytics 工作區位於租使用者 'B',請使用下列兩種方法之一:

  1. Azure 資料總管可讓您為不同租用戶中的主體新增角色。 將租用戶 'B' 中的使用者識別碼新增為 Azure 資料總管叢集上的授權使用者。 驗證 Azure 資料總管叢集上的 'TrustedExternalTenant' 屬性是否包含租用戶 'B'。 在租用戶 'B' 中完整地執行交叉查詢。

  2. 使用 Lighthouse 將 Azure 監視器資源投射到租用戶 'A'。

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

Kusto Explorer 會自動將您登入使用者帳戶原先所屬的租用戶。 若要使用相同的使用者帳戶存取其他租用戶中的資源,必須在連接字串中明確指定 tenantIdData Source=https://ade.applicationinsights.io/subscriptions/SubscriptionId/resourcegroups/ResourceGroupName;Initial Catalog=NetDefaultDB;AAD Federated Security=True;Authority ID=TenantId

函式支援性

Azure 資料總管跨服務查詢支援 Application Insights 和 Log Analytics 的函式。 這項功能可讓跨叢集查詢直接參考 Azure 監視器表格式函式。 跨服務查詢支援下列命令:

  • .show functions
  • .show function {FunctionName}
  • .show database {DatabaseName} schema as json

下圖描述從 Azure Data Explorer Web UI 查詢表格式函式的範例。 若要使用函式,請在查詢視窗中執行名稱。

顯示從 Azure Data Explorer Web U I 查詢表格式函式的螢幕快照。

其他語法範例

呼叫 Application Insights 或 Log Analytics 叢集時,可以使用下列語法選項:

語法描述 Application Insights Log Analytics
資料庫位在只包含此訂用帳戶中已定義資源的叢集中 (建議用於跨叢集查詢) 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.insights/components/<ai-app-name>').database('<ai-app-name>) 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>').database('<workspace-name>)
包含此訂用帳戶中所有應用程式/工作區的叢集 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>) 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>)
叢集包含訂用帳戶中屬於此資源群組成員的所有應用程式/工作區 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>) 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>)
僅包含此訂用帳戶中已定義資源的叢集 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.insights/components/<ai-app-name>) 叢集 (『https://adx.monitor.azure.com/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>)
若為 UsGov 中的端點 叢集 (『https://adx.monitor.azure.us/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>)
若為 China 21Vianet 中的端點 叢集 (『https://adx.monitor.azure.cn/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/microsoft.operationalinsights/workspaces/<workspace-name>)