Skip to content

Query Workbench


The Query Workbench lets you write, run, and debug queries in the console. You can use DQL, Simple Query, or PromQL, view table and JSON results, save frequently used statements for reuse, or save queries to a dashboard.

Open the Workbench

In the toolbar at the top of the console, click the Query Workbench icon to open the workbench. The workbench is displayed as a pop-up window; when you close it, you return to the original page.

Start a Query

  1. In the upper-left corner of the editor, select a query mode. The default is DQL.
  2. In the Time Widget in the upper-right corner, select the query time range. The default is Last 1 hour. For how to select a time range, see Time Widget.
  3. Enter a query statement, or in Simple Query mode, select data and query conditions.
  4. Click Run.
  5. View the Query Results below; you can also switch to JSON or Query Inspector.

You can drag the divider between the editor and the results area to adjust the height of both areas.

The time range is set centrally at the top of the workbench. After you change the time range or query content, you must click Run again for existing results to update.

Write a Query

Select a Query Mode

Select a mode from the drop-down menu in the upper-left corner of the editor:

Mode How to use
DQL Write query statements manually to query metrics, logs, events, and other data. For syntax and functions, see DQL and DQL Functions
Simple Query Build a query by selecting the data type, data source, fields, functions, and filter conditions; the system generates the corresponding DQL
PromQL Use PromQL to query metrics; this option is displayed only for workspaces whose metrics are stored in GuanceDB. For syntax, see PromQL

DQL and Simple Query use the same query language. After adjusting conditions in Simple Query, switch back to DQL to view the generated statement. When writing complex expressions or subqueries, you can use DQL mode directly.

Statements are not automatically converted between DQL and PromQL: if the current tab already contains query content, switching the language creates a new blank tab and keeps the original query; if the current tab is empty, the switch occurs directly.

Use Simple Query

  1. Select the data type to query, for example, metrics or logs.
  2. Select the data source and fields; when querying logs, you can select a Log Index.
  3. Set options such as aggregation functions, filter conditions, and grouping as needed.
  4. Click Run to view the results, or switch to DQL to inspect the complete generated statement.

The options available vary by data type. After a Simple Query is saved, it is recorded as DQL and opens in DQL mode the next time.

Use the Code Editor

The DQL and PromQL editors support line numbers, syntax highlighting, autocompletion, bracket matching, multi-line editing, and undo.

After you enter a statement, the editor displays the syntax validation status. If there is a syntax error, hover over the error status to view the reason, fix the error, and then run the query.

The upper-right corner of the editor provides the following actions:

Action Description
Format Adjust the spaces, line breaks, and indentation of the current statement for readability; formatting is unavailable when there is a syntax error
Copy Query Copy the complete query statement in the current tab
Help Open DQL syntax help
Save Query Save the current statement to Saved Queries; see Save a Query for details
Run Run the query in the current tab; unavailable when the query is empty or has a syntax error

The Format and Copy Query buttons are displayed when the code editor contains content.

PromQL Query Types

After selecting PromQL, you can switch the query type next to the mode selector:

Type Applicable results
Range Query a metric series over a time range and view results that change over time
Instant Query metric results at a single point in time

Generate DQL from Natural Language

In DQL mode, you can describe the query objective in the input box above the editor and click Generate DQL to have AI generate a statement.

  1. Enter the data you want to query, the filter conditions, and the statistical objective.
  2. Click Generate DQL and wait for the generated result to be written to the editor in the current tab.
  3. Check the data source, fields, and query conditions, modify them as needed, and then click Run.

If no time is specified, the generated query uses the page time range. The generated result replaces the query statement in the current tab; if you need to keep the original statement, create a new tab first. The query is not run automatically after generation, and existing results are not refreshed.

The generation process does not verify workspace fields one by one. Before execution, check the fields, units, and statistical definitions. For details, see AI-assisted DQL generation.

This feature is currently in Beta and is available only in DQL mode. The workspace must have AI enabled and have available TOBY AI credits; if the credit balance is insufficient or the daily usage limit is reached, the page displays the reason. Read-only members cannot use AI generation.

Manage Multiple Queries

Click + in the tab bar to create a query. You can open up to 10 tabs at the same time. A new tab inherits the query mode of the current tab; for PromQL, it also inherits the Range or Instant type.

Each tab retains its own query content and run results. Switch tabs to continue editing or view the results of the last run of that query; the query is not run again automatically.

Click the close icon on a tab to remove that query. After you close the last tab, the workbench keeps one blank DQL tab.

Closing a tab or the entire workbench clears the corresponding unsaved content and run results. Save statements that you need to reuse over the long term; statements that have already been executed can also be found in Query History.

View Query Results

After running a query, you can switch between the result tabs below:

Tab Description
Query Results Displays fields and data in a table; the time column is displayed in the current time zone
JSON View the result rows of this query in JSON format
Query Inspector View the query type, time range, duration, result count, status, and query statement of this execution

The right side of the results area displays the execution status, duration, and number of rows. The workbench displays up to 500 rows; the row count here is the number of results displayed this time, not the total amount of all matching data. The JSON view also uses the results of this execution.

Sampling and Streaming Aggregation Notifications

When the results use sampled data or streaming aggregation, the results area displays the corresponding notification icon; hover over it to view an explanation.

Click the sampling notification icon and confirm to temporarily disable sampling and rerun the current query. Disabling sampling may increase query duration. The streaming aggregation icon only indicates that this query uses streaming aggregation.

Save and Reuse Queries

Save a Query

  1. Write a query in the editor and click Save Query.
  2. Enter a Query Name; optionally enter a Description.
  3. Click Save.

The query name is required and can contain up to 80 characters; the description can contain up to 240 characters. Each account can save up to 100 queries in each workspace.

Saved queries are stored on the server and isolated by account and workspace for your own use in the corresponding workspace. The saved content includes the name, description, query statement, query language, and PromQL query type; it does not include run results or the time range in the Time Widget at the top.

Clicking save again creates a new record instead of overwriting the original record. After opening a saved query and modifying it, you can save it under a new name, or delete the old record when you confirm it is no longer needed.

Open and Manage Saved Queries

Click Saved Queries on the right side of the tab bar. In the panel on the right:

  • Search by query name or query statement, or filter by DQL or PromQL; the list is sorted by most recent update time.
  • Click a record to load the query into the editor. If the current tab already contains content, it opens in a new tab.
  • The query is not run automatically after loading. Confirm the current time range and click Run to get results.
  • Click the delete button on the right side of a record, or select multiple records and click Delete, then confirm to remove the records; Select All selects only the records on the current page. Deleted records cannot be restored in the page.

Query History

Switch to Query History to view executed queries. History records display the query statement, execution time, success or failure status, duration, and number of result rows, and support searching by statement content and copying.

Clicking a history record loads the statement and immediately reruns it using the current workbench time range. If the current tab already contains content, a new tab is created. History records do not save the results from that time, and the data after rerunning may differ from the original results.

Query History is stored locally in the current browser, separated by workspace, and retains records from the last 7 days, up to 100 records. After you change browsers or clear local storage, the original history can no longer be viewed; for statements that need to be retained, use Save Query.

Export and Save to Dashboard

After a query succeeds, click the Result Actions icon in the upper-right corner of the results area and select Export CSV or Save to Dashboard.

Export CSV

For DQL queries, you can select the following export methods:

Option Exported content
Default Export the current run results directly without rerunning the query, up to 500 rows
1K, 5K, 10K Rerun using the query statement and time range from this execution with sampling disabled, and set 1,000, 5,000, or 10,000 rows as the export limit

1K, 5K, and 10K exports use the query conditions from the last execution; even if the editor or Time Widget is subsequently modified, the new conditions that have not yet been run are not used. To export data for new conditions, rerun the query first.

Exports that rerun the query may take longer than the default export, and you can cancel the task during export. The actual number of rows depends on the amount of matching data; the selected number is the upper limit.

PromQL queries export the current run results directly as CSV and do not provide the row count options above.

Save to Dashboard

  1. In Result Actions, select Save to Dashboard.
  2. Enter the chart title and select the target dashboard; if you have creation permissions, you can also create a dashboard.
  3. After confirmation, save the current query configuration as a table chart in the dashboard.

This action saves the query configuration, and the chart subsequently runs the query to obtain data. If the query statement, query type, or time range is modified after running, the system indicates that the current results may be inconsistent with the configuration to be saved; you can cancel and rerun, or confirm to continue saving the current configuration.

Common Shortcuts

Action Windows / Linux macOS
Open or close the Query Workbench Alt + Q Option + Q
Run the current query Ctrl + Enter ⌘ + Enter
Open the Save Query window in the code editor Ctrl + S ⌘ + S