QueryHub Queries and Applications¶
After you complete the QueryHub configuration in Integrations > External Data Sources and confirm that it takes effect, you can select the data source in Metrics Analysis or in dashboard charts. The current user must have the corresponding query permissions, and the available query modes depend on the modes actually enabled for the selected instance.
Query in Metrics Analysis¶
- Go to Metrics > Metrics Analysis.
- Click + Add Data Source below the query area to add a data source query row.
- In the Data Source drop-down of that row, select the configured QueryHub data source by connection name.
- To the right of the data source, select Native Query or DQL Like, and manually enter the corresponding query statement or expression in the input box.
- Click the refresh button in the upper-right corner of the page, view the query results below, and select a display mode that suits the result structure.
Here, + Add Data Source adds a query row. To add or modify connection information, still use Integrations > External Data Sources.
Query in Dashboard Charts¶
- Go to Scenes > Dashboards and open the target dashboard.
- Create a chart, or select Modify in the menu of an existing chart to open the chart editing page.
- In the chart query area that supports external data sources, click Add Data Source and select the configured QueryHub data source.
- Select Native Query or DQL Like, enter the query content, and view the preview results.
- Based on the results, set the chart display items such as dimensions and values, then confirm and save the chart.
After saving, the chart retains the selected data source and query configuration; subsequent refreshes still require the query permissions of that data source. For general chart operations, see Add Chart.
Select a Query Mode¶
Native Query¶
After you select Native Query, enter SQL or a complete query JSON in the input box based on the data source type:
| Data Source | Native query editor content | How to view sources and fields |
|---|---|---|
| MySQL | SQL statement, one at a time | Manually run SHOW TABLES and SHOW COLUMNS |
| PostgreSQL | SQL statement, using the configured Schema | Manually query the table and column information in information_schema |
| Prometheus | Complete JSON: operation is query or query_range, and PromQL is placed in statement |
View the series names and labels of current samples through a scoped query |
| Elasticsearch | Complete JSON: operation is search, and the request body is placed in arguments.body |
The index range depends on the instance configuration; fields are viewed from hit document samples; view the complete mapping on the data source side |
| MongoDB | Complete JSON: operation is find, and parameters such as filters and projections are placed in arguments |
Databases and collections depend on the instance configuration; fields are viewed from sample documents |
Native queries and source and field viewing examples are all in the corresponding type sections above. Replace the query objects and fields in the examples with actual values, enter them in the input box, and then click Refresh in the upper-right corner.
DQL Like¶
After you select DQL Like, manually enter a complete expression in the input box to specify the query object, returned fields, and filter conditions.
- After selecting the data source, switch to DQL Like.
- Enter the complete DQL Like expression in the input box.
- Set
sourceto the corresponding data source type, replacedatasourcewith the ID of the currently selected instance, and then modify the query object, fields, and conditions based on the actual data. You can view and copy the instance ID in the list or details of Integrations > External Data Sources. - Click Refresh in the upper-right corner of the page to view the results.
When you use sorting, aggregation, or grouping, write them according to the DQL Like syntax, and confirm that the query object and fields meet the requirements of the selected data source.
DQL Like is a QueryHub query syntax and differs from the regular DQL used to query logs and metrics in a workspace. The source and datasource in the expression must be consistent with the data source type and instance selected on the page.
All examples are read-only. The database account itself must also have read permissions for the queried objects.
How the Time Range Takes Effect¶
- Native queries such as MySQL and PostgreSQL are executed according to the conditions in the statement. When you need to limit the time, write filter conditions using actual time fields.
- Prometheus range queries reference
#{startTime}and#{endTime}througharguments.startandarguments.endin the JSON; the frontend automatically converts the chart time to seconds;arguments.stepis also in seconds. Instant queries and range queries have different result meanings. - DQL Like queries are executed according to the time conditions specified in the expression.
After a Prometheus range query references the above chart time variables, it changes with the page time range. MySQL and PostgreSQL SQL still need corresponding time filter conditions.
How Query Results Are Displayed¶
| Returned content | How to view |
|---|---|
| Regular rows and columns from MySQL and PostgreSQL | Displayed according to the columns, types, and row order returned by the server; you can first use a table to check details |
| Prometheus samples | The "Name" and "Tags" in the Studio table come from the series' name and tags; the time column is time, the API uses Unix milliseconds, and the page displays it formatted; the numeric column name varies with the metric name or expression |
| Elasticsearch and MongoDB documents | Use a table chart and expand the document JSON to view it; JSON fields remain nested and do not automatically become separate columns due to the selection of projected fields |
| Empty results | The query may have succeeded but no records matched; check the time, filter conditions, and configured range |
| Truncated results | Only part of the data was returned; follow the page prompts to narrow the range and reduce the returned volume, then retry; do not treat it as complete result statistics |
| Query failure | Keep the input and modify and retry based on the masked error; an interrupted or incompletely finished return is not treated as a successful result |
When displaying, preserve the types and NULL meanings returned by the server, do not automatically replace NULL with 0, and do not arbitrarily convert high-precision values into low-precision numbers.
When selecting a chart, first confirm the result structure: use a table to view details first; trend charts require identifiable time and values; configure the display of grouped statistical results based on the actual dimensions and values. The available chart range is subject to the current query entry point.
FAQ¶
What should I do if I cannot find the instance or cannot query?¶
Confirm the current workspace, the configuration effective status, and the query permissions.
What should I do if the instance mismatch is reported?¶
Check datasource and source in the DQL Like expression to ensure that they are consistent with the instance ID and data source type selected on the page. After switching the data source, you also need to update the corresponding values in the expression.
Why can't I see tables, indexes, or collections?¶
Check the instance configuration range and the data source account permissions. Queries for viewing sources are also subject to these limits.
What should I do if a field is missing from the returned document?¶
Confirm whether the sample document contains that field, and read a limited number of additional samples if necessary.
What should I do if the query is too slow or the results are limited?¶
Narrow the query range, add filter conditions, and use SQL LIMIT, Elasticsearch size, or MongoDB limit to control the returned volume.

