快速入门:使用 Azure Resource Graph Explorer 运行第一个 Resource Graph 查询Quickstart: Run your first Resource Graph query using Azure Resource Graph Explorer

可以直接在 Azure 门户中通过 Azure Resource Graph Explorer 使用 Azure Resource Graph 的强大功能。The power of Azure Resource Graph is available directly in Azure portal through Azure Resource Graph Explorer. Resource Graph Explorer 提供有关可查询的 Azure 资源管理器资源类型和属性的可浏览信息。Resource Graph Explorer provides browsable information about the Azure Resource Manager resource types and properties that you can query. Resource Graph Explorer 还提供一个整洁的界面用于处理多个查询、评估结果,甚至是将某些查询的结果转换为可固定到 Azure 仪表板的图表。Resource Graph Explorer also provides a clean interface for working with multiple queries, evaluating the results, and even converting the results of some queries into a chart that can be pinned to an Azure dashboard.

在本快速入门结束时,你已使用 Azure 门户和 Resource Graph Explorer 运行第一个 Resource Graph 查询,并已将结果固定到仪表板。At the end of this quickstart, you'll have used Azure portal and Resource Graph Explorer to run your first Resource Graph query and pinned the results to a dashboard.


如果没有 Azure 订阅,请在开始前创建一个试用版订阅帐户。If you don't have an Azure subscription, create a trial subscription account before you begin.

运行首个 Resource Graph 查询Run your first Resource Graph query

打开 Azure 门户,遵循以下步骤找到并使用 Resource Graph Explorer 运行第一个 Resource Graph 查询:Open the Azure portal to find and use the Resource Graph Explorer following these steps to run your first Resource Graph query:

  1. 在左侧窗格中,选择“所有服务”。Select All services in the left pane. 搜索并选择 Resource Graph ExplorerSearch for and select Resource Graph Explorer.

  2. 在窗口中的“查询 1”部分输入查询 Resources | project name, type | limit 5,然后选择“运行查询”。 In the Query 1 portion of the window, enter the query Resources | project name, type | limit 5 and select Run query.


    由于此查询示例未提供排序修饰符(例如 order by),因此多次运行此查询可能会为每个请求生成一组不同的资源。As this query example doesn't provide a sort modifier such as order by, running this query multiple times is likely to yield a different set of resources per request.

  3. 在“结果”选项卡中查看查询响应。选择“消息”选项卡,以查看有关查询的详细信息,包括结果计数和查询持续时间。Review the query response in the Results tab. Select the Messages tab to see details about the query, including the count of results and duration of the query. 出现的任何错误将显示在此选项卡下。Errors, if any, are displayed under this tab.

  4. 更新查询,以将 order by 条件指定为 Name 属性:Resources | project name, type | limit 5 | order by name ascUpdate the query to order by the Name property: Resources | project name, type | limit 5 | order by name asc. 然后选择“运行查询”。Then, select Run query.


    与第一个查询一样,多次运行此查询可能会为每个请求生成一组不同的资源。Just as with the first query, running this query multiple times is likely to yield a different set of resources per request. 查询命令的顺序非常重要。The order of the query commands is important. 在本例中,order by 位于 limit 之后。In this example, the order by comes after the limit. 命令按此顺序执行,首先会限制查询结果,然后对它们进行排序。This command order first limits the query results and then orders them.

  5. 将查询更新为先按 Name 属性应用 order by,然后对前五个结果应用 limitResources | project name, type | order by name asc | limit 5Update the query to first order by the Name property and then limit to the top five results: Resources | project name, type | order by name asc | limit 5. 然后选择“运行查询”。Then, select Run query.

假设环境中没有任何变化,则多次运行最后一个查询时,返回的结果将是一致的且按 Name 属性排序,但仍限制为前五个结果。When the final query is run several times, assuming that nothing in your environment is changing, the results returned are consistent and ordered by the Name property, but still limited to the top five results.

架构浏览器Schema browser

架构浏览器位于 Resource Graph Explorer 的左窗格中。The schema browser is located in the left pane of Resource Graph Explorer. 此资源列表显示 Azure 资源的所有资源类型,这些类型受 Azure Resource Graph 的支持,并且存在于你有权访问的租户中。This list of resources shows all the resource types of Azure resources that are both supported by Azure Resource Graph and that exist in a tenant that you have access to. 展开资源类型或附属属性会显示可用于创建 Resource Graph 查询的子属性。Expanding a resource type or subproperties show child properties that can be used to create a Resource Graph query.

选择资源类型会将 where type =="<resource type>" 放入查询框中。Selecting the resource type places where type =="<resource type>" into the query box. 选择一个子属性会将 where <propertyName> == "INSERT_VALUE_HERE" 添加到查询框中。Selecting one of the child properties adds where <propertyName> == "INSERT_VALUE_HERE" into the query box. 在架构浏览器中,可以十分方便地发现可在查询中使用的属性。The schema browser is a great way to discover properties for use in queries. 请确保将 INSERT_VALUE_HERE 替换为自己的值,并调整包含条件、运算符和函数的查询,以获得预期结果。Be sure to replace INSERT_VALUE_HERE with your own value, adjust the query with conditions, operators, and functions to achieve your intended results.

基于 Resource Graph 查询创建图表Create a chart from the Resource Graph query

运行前面的查询后,如果你选择“图表”选项卡,则会看到一条消息,指出“该结果集与饼图可视化效果不兼容。”After running the previous query, if you select the Charts tab, you get a message that "the result set isn't compatible with a pie chart visualization." 列出结果的查询无法生成图表,但提供资源计数的查询则可以。Queries that list results can't be made into a chart, but queries that provide counts of resources can. 让我们使用示例查询 - 按 OS 类型统计虚拟机数目,基于 Resource Graph 查询创建可视化效果。Using the Sample query - Count virtual machines by OS type, let's create a visualization from the Resource Graph query.

  1. 在窗口中的“查询 1”部分输入以下查询,然后选择“运行查询”。 In the Query 1 portion of the window, enter the following query and select Run query.

    | where type =~ 'Microsoft.Compute/virtualMachines'
    | summarize count() by tostring(properties.storageProfile.osDisk.osType)
  2. 选择“结果”选项卡,可以看到,此查询的响应提供了计数。Select the Results tab and note that the response for this query provides counts.

  3. 选择“图表”选项卡。现在,查询将会生成可视化效果。Select the Charts tab. Now, the query results in visualizations. 在“选择图表类型...”中将类型更改为“条形图”或“圆环图”,以体验各种可用的可视化选项。 Change the type from Select chart type... to either Bar chart or Donut chart to experiment with the available visualization options.

将查询可视化效果固定到仪表板Pin the query visualization to a dashboard

如果查询返回的结果可以可视化,则你可以将该数据可视化效果固定到某个仪表板。When you have results from a query that can be visualized, that data visualization can then be pinned to one of your dashboards. 运行前面的查询后,请执行以下步骤:After running the previous query, follow these steps:

  1. 选择“保存”,并提供名称“按 OS 类型统计的 VM 数目”。Select Save and provide the name "VMs by OS Type". 然后在右窗格底部选择“保存”。Then select Save at the bottom of the right pane.

  2. 选择“运行查询”,以重新运行现已保存的查询。Select Run query to rerun the query now that it's been saved.

  3. 在“图表”选项卡上,选择一种数据可视化效果。On the Charts tab, select a data visualization. 然后选择“固定到仪表板”。Then select Pin to dashboard.

  4. 选择显示的门户通知,或者在左窗格中选择“仪表板”。Either select the portal notification that appears or select Dashboard from the left pane.

现在,该查询会显示在仪表板上,其磁贴标题与查询名称相匹配。The query is now available on your dashboard with the title of the tile matching the query name. 如果在固定时该查询未保存,则其名称将是“查询 1”。If the query was unsaved when it was pinned, it's named 'Query 1' instead.

每当加载仪表板时,该查询和生成的数据可视化效果就会运行并更新,直接在工作流中提供 Azure 环境的实时动态见解。The query and resulting data visualization run and update each time the dashboard loads, providing real-time and dynamic insights to your Azure environment directly in your workflow.


也可以将生成列表的查询固定到仪表板。Queries that result in a list can also be pinned to the dashboard. 此功能并不局限于查询的数据可视化。The feature isn't limited to data visualizations of queries.

导入示例 Resource Graph Explorer 面板Import example Resource Graph Explorer dashboards

若要提供 Resource Graph 查询示例并了解如何使用 Resource Graph Explorer 增强 Azure 门户工作流,请尝试以下示例仪表板。To provide examples of Resource Graph queries and how Resource Graph Explorer can be used to enhance your Azure portal workflow, try out these example dashboards.


上述示例仪表板屏幕截图中的计数和图表根据 Azure 环境的不同而异。Counts and charts in the above example dashboard screenshots vary depending on your Azure environment.

  1. 选择并下载想要评估的示例仪表板。Select and download the sample dashboard you want to evaluate.

  2. 在 Azure 门户上的左窗格中选择“仪表板”。In Azure portal, select Dashboard from the left pane.

  3. 选择“上传”,找到并选择已下载的示例仪表板文件。Select Upload, then locate and select the downloaded sample dashboard file. 然后选择“打开”。Then select Open.

此时会自动显示已导入的仪表板。The imported dashboard is automatically displayed. 由于该仪表板现已加载到 Azure 门户中,因此你可以根据需要进行探索和更改,或者基于示例创建可与团队共享的新仪表板。Since it now exists in your Azure portal, you may explore and make changes as needed or create new dashboards from the example to share with your teams. 有关使用仪表板的详细信息,请参阅在 Azure 门户中创建和共享仪表板For more information about working with dashboards, see Create and share dashboards in the Azure portal.

清理资源Clean up resources

若要从 Azure 门户环境中删除示例 Resource Graph 仪表板,可执行以下步骤:If you wish to remove the sample Resource Graph dashboards from your Azure portal environment, you can do so with the following steps:

  1. 在左窗格中选择“仪表板”。Select Dashboard from the left pane.

  2. 在仪表板下拉列表中,选择要删除的示例 Resource Graph 仪表板。From the dashboard drop-down, select the sample Resource Graph dashboard you wish to delete.

  3. 在仪表板顶部的菜单中选择“删除”,然后选择“确定”以确认。 Select Delete from the dashboard menu at the top of the dashboard and select Ok to confirm.

后续步骤Next steps

本快速入门已介绍如何使用 Azure Resource Graph 资源管理器运行第一个查询,并提供了 Resource Graph 支持的仪表板示例。In this quickstart, you've used Azure Resource Graph Explorer to run your first query and looked at dashboard examples powered by Resource Graph. 若要详细了解 Resource Graph 语言,请继续阅读查询语言详细信息页。To learn more about the Resource Graph language, continue to the query language details page.