工作簿资源参数Workbook resource parameters

使用资源参数可以选取工作簿中的资源。Resource parameters allow picking of resources in workbooks. 在设置从中获取数据的范围时,资源参数非常有用。This is useful in setting the scope from which to get the data from. 例如,用户可以通过资源参数选择 VM 集,然后,图表在呈现数据时可以使用这些 VM。An example is allowing users to select the set of VMs, which the charts later will use when presenting the data.

资源选取器中的值可以来自工作簿上下文、静态列表或 Azure Resource Graph 查询。Values from resource pickers can come from the workbook context, static list or from Azure Resource Graph queries.

创建资源参数(工作簿资源)Creating a resource parameter (workbook resources)

  1. 从编辑模式下的空工作簿开始操作。Start with an empty workbook in edit mode.
  2. 从工作簿内的链接中选择“添加参数”。Choose Add parameters from the links within the workbook.
  3. 单击蓝色的“添加参数”按钮。Click on the blue Add Parameter button.
  4. 在弹出的“新建参数”窗格中,输入:In the new parameter pane that pops up enter:
    1. 参数名称:ApplicationsParameter name: Applications
    2. 参数类型:Resource pickerParameter type: Resource picker
    3. 必需:checkedRequired: checked
    4. 允许多选:checkedAllow multiple selections: checked
  5. 从以下位置获取数据:Workbook ResourcesGet data from: Workbook Resources
  6. 仅包括资源类型:Application InsightsInclude only resource types: Application Insights
  7. 从工具栏中选择“保存”以创建参数。Choose 'Save' from the toolbar to create the parameter.

显示如何使用工作簿资源创建资源参数的插图

创建资源参数 (Azure Resource Graph)Creating a resource parameter (Azure Resource Graph)

  1. 从编辑模式下的空工作簿开始操作。Start with an empty workbook in edit mode.
  2. 从工作簿内的链接中选择“添加参数”。Choose Add parameters from the links within the workbook.
  3. 单击蓝色的“添加参数”按钮。Click on the blue Add Parameter button.
  4. 在弹出的“新建参数”窗格中,输入:In the new parameter pane that pops up enter:
    1. 参数名称:ApplicationsParameter name: Applications
    2. 参数类型:Resource pickerParameter type: Resource picker
    3. 必需:checkedRequired: checked
    4. 允许多选:checkedAllow multiple selections: checked
  5. 从以下位置获取数据:QueryGet data from: Query
    1. 查询类型:Azure Resource GraphQuery Type: Azure Resource Graph
    2. 订阅:Use default subscriptionsSubscriptions: Use default subscriptions
    3. 在查询控件中添加此片段In the query control, add this snippet
    where type == 'microsoft.insights/components'
    | project value = id, label = name, selected = false, group = resourceGroup
    
  6. 从工具栏中选择“保存”以创建参数。Choose 'Save' from the toolbar to create the parameter.

显示如何使用 Azure Resource Graph 创建资源参数的插图

备注

Azure Resource Graph 尚未在所有云中推出。Azure Resource Graph is not yet available in all clouds. 如果选择此方法,请确保你的目标云支持 Azure Resource Graph。Ensure that it is supported in your target cloud if you choose this approach.

Azure Resource Graph 文档Azure Resource Graph documentation

创建资源参数(JSON 列表)Creating a resource parameter (JSON list)

  1. 从编辑模式下的空工作簿开始操作。Start with an empty workbook in edit mode.
  2. 从工作簿内的链接中选择“添加参数”。Choose Add parameters from the links within the workbook.
  3. 单击蓝色的“添加参数”按钮。Click on the blue Add Parameter button.
  4. 在弹出的“新建参数”窗格中,输入:In the new parameter pane that pops up enter:
    1. 参数名称:ApplicationsParameter name: Applications
    2. 参数类型:Resource pickerParameter type: Resource picker
    3. 必需:checkedRequired: checked
    4. 允许多选:checkedAllow multiple selections: checked
  5. 从以下位置获取数据:JSONGet data from: JSON
    1. 在内容控件中添加此 JSON 片段In the content control, add this json snippet
    [
        { "value":"/subscriptions/<sub-id>/resourceGroups/<resource-group>/providers/<resource-type>/acmeauthentication", "label": "acmeauthentication", "selected":true, "group":"Acme Backend" },
        { "value":"/subscriptions/<sub-id>/resourceGroups/<resource-group>/providers/<resource-type>/acmeweb", "label": "acmeweb", "selected":false, "group":"Acme Frontend" }
    ]
    
    1. 点击蓝色的“更新”按钮。Hit the blue Update button.
  6. (可选)将 Include only resource types 设置为 Application InsightsOptionally set the Include only resource types to Application Insights
  7. 从工具栏中选择“保存”以创建参数。Choose 'Save' from the toolbar to create the parameter.

引用资源参数Referencing a resource parameter

  1. 在工作簿中添加查询控件,然后选择 Application Insights 资源。Add a query control to the workbook and select an Application Insights resource.
  2. 使用“Application Insights”下拉列表将参数绑定到控件。Use the Application Insights drop down to bind the parameter to the control. 这会将查询范围设置为参数在运行时返回的资源。Doing this sets the scope of the query to the resources returned by the parameter at run time.
  3. 在 KQL 控件中添加此片段In the KQL control, add this snippet
    requests
    | summarize Requests = count() by appName, name
    | order by Requests desc
    
  4. 运行查询以查看结果。Run query to see the results.

显示查询控件中引用的资源参数的插图

此方法可用于将资源绑定到其他控件(例如指标)。This approach can be used to bind resources to other controls like metrics.

资源参数选项Resource parameter options

参数Parameter 说明Explanation 示例Example
{Applications} 选定的资源 IDThe selected resource ID /subscriptions//resourceGroups//providers//acmeauthentication/subscriptions//resourceGroups//providers//acmeauthentication
{Applications:label} 所选资源的标签The label of the selected resource acmefrontend
{Applications:value} 所选资源的值The value of the selected resource '/subscriptions//resourceGroups//providers//acmeauthentication''/subscriptions//resourceGroups//providers//acmeauthentication'
{Applications:name} 所选资源的名称The name of the selected resource acmefrontend
{Applications:resourceGroup} 所选资源的资源组The resource group of the selected resource acmegroup
{Applications:resourceType} 所选资源的类型The type of the selected resource microsoft.insights/componentsmicrosoft.insights/components
{Applications:subscription} 所选资源的订阅The subscription of the selected resource
{Applications:grid} 显示资源属性的网格。A grid showing the resource properties. 调试时可用于在文本块中呈现内容Useful to render in a text block while debugging

后续步骤Next steps

  • 开始详细了解工作簿丰富的可视化效果选项。Get started learning more about workbooks many rich visualizations options.
  • 控制并共享对工作簿资源的访问权限。Control and share access to your workbook resources.