All Products
Search
Document Center

Resource Management:Use a custom query template to query resources

Last Updated:Oct 31, 2023

This topic describes how to create a custom query template and use the custom query template to query resources.

Step 1: Select a query scope

You can select a query scope for resources. This can help reduce unnecessary searches and data redundancy and help you quickly obtain the desired query result.

  1. Log on to the Resource Management console.

  2. In the left-side navigation pane, choose Resource Center > Advanced.

  3. On the Advanced page, click Change Query Scope.

  4. Select a query scope.

    • If the current logon account is an Alibaba Cloud account for which cross-account resource search is not enabled, you can choose to perform a query within the current logon account or within a specified resource group.

    • If the current logon account is the management account of a resource directory and cross-account resource search is enabled for the account, you can choose to perform a query within the current logon account or across accounts.

      • Current logon account: You can specify the current logon account or a specific resource group as the query scope.

      • Cross accounts: You can specify the entire resource directory, a specific folder, a specific member, or a specific resource group as the query scope.

Step 2: Create a custom query template

  1. Log on to the Resource Management console.

  2. In the left-side navigation pane, choose Resource Center > Advanced.

  3. In the code editor displayed on the Temporary _Query_1 tab, write the query statement. Alternatively, click the + icon to expand a new tab and write the query statement in the code editor displayed on the tab.

    The query statement that you write must comply with the basic SQL syntax. For more information about the basic SQL syntax, see Basic SQL syntax.

    The system provides the following features to help you quickly write the query statement:

    • Automatic fill: The Resource Property pane displays the Alibaba Cloud services, resource types, and resource properties that are supported by the advanced search feature. You can click the required resource types and resource properties to add them to code in the code editor.

    • Code hinting and automatic completion: Resource Management also provides the code hinting feature and automatic completion feature for advanced search. When you write code in the code editor, the system provides code hints such as keywords and properties based on the content that you enter. This can help you quickly complete the writing of the query statement.

  4. Click Run to run the code and check whether the query result meets your expectations.

  5. Click Save to save the query statement as a custom query template.

Note

You can modify the query statement in a sample query template or an existing custom query template and click Save As to save the modified template as a new custom query template.

Step 3: Execute the custom query template

  1. On the Advanced page, click the Quick Start tab. In the Custom Query Template section of the Quick Start tab, find the custom query template that you created.

  2. Click Open.

  3. In the code editor in the upper part of the Advanced page, view the query statement in the custom query template.

  4. Click Run.

Step 4: View and download the query result

Click the Query Result tab and view the query result.

View the query result in a list

Click the List subtab and view the query result in a list. You can turn on the Format switch in the upper-right corner of the List subtab. This way, the values of specific property fields are converted from IDs into names.

结果列表.jpg

View the query result in a chart

If the query result contains only two columns: a column whose values are strings and a column whose values are numeric values, you can click the Chart subtab of the Query Result tab to view the query result in a chart. Click the 设置.jpg icon in the upper-right corner of the Chart subtab. In the List Settings dialog box, select Pie or Bar for the Chart Type parameter.

Pie chart

image.png

Bar chart

image.png

Download the query result

You can download the query result that is displayed in a list as a CSV file and save the CSV file to your on-premises machine.

You can choose to download the query result that is converted or is not converted.

  • If you download the query result that is converted, you can obtain a file that contains converted data. The conversion makes specific data easier to read.

  • If you download the query result that is not converted, you can obtain a data file that contains the raw query result.

You can use a data analysis tool to process the downloaded query result and gain in-depth insights into the data.