<@U0A71G31CDV> how can I catch query statitstics f...
# questions-and-troubleshooting
z
@Rocky how can I catch query statitstics from auditloader to grafana?
1
r
To visualize query statistics from AuditLoader in Grafana, you must first ensure your audit logs are being loaded into a StarRocks table, and then connect Grafana to that table using the MySQL data source. 1. Ensure AuditLoader is Populating a Table The AuditLoader plugin captures logs from
fe.audit.log
and loads them into a StarRocks table (usually named
starrocks_audit_tbl__
). * Verify Data: Run a query in StarRocks to ensure logs are arriving:
Copy code
sql
    SELECT * FROM starrocks_audit_db*.starrocks_audit_tbl* LIMIT 10;
If you haven't set this up yet, follow the AuditLoader documentation to create the database/table and install the plugin. 2. Connect Grafana to StarRocks Since StarRocks is MySQL-compatible, you can use the built-in MySQL data source in Grafana to query the audit table directly. 1. In Grafana, go to Connections > Data sources. 2. Click Add data source and select MySQL. 3. Configure the settings: * Host:
<FE_IP>:9030
* Database:
starrocks_audit_db__
* User: Your StarRocks user (ensure it has
SELECT
privileges on the audit table). * Password: Your StarRocks password. 3. Create Dashboards Once connected, you can create panels using SQL. Here are common metrics you can visualize: * Query Count Over Time:
Copy code
sql
    SELECT $__timeGroupAlias(timestamp, 1m), count(*) as query_count
    FROM starrocks_audit_tbl__
    WHERE $__timeFilter(timestamp)
    GROUP BY 1 ORDER BY 1;
* Slow Queries (Top 10):
Copy code
sql
    SELECT stmt, queryTime, user, clientIp
    FROM starrocks_audit_tbl__
    WHERE $__timeFilter(timestamp)
    ORDER BY queryTime DESC
    LIMIT 10;
* Average CPU/Memory Cost per User:
Copy code
sql
    SELECT user, avg(cpuCostNs/1000000) as avg_cpu_ms, avg(memCostBytes/1024/1024) as avg_mem_mb
    FROM starrocks_audit_tbl__
    WHERE $__timeFilter(timestamp)
    GROUP BY user;
Note on Official Templates While StarRocks provides official Grafana templates for system metrics (via Prometheus), there is no single official JSON template for AuditLoader tables because table schemas can vary by version. Most users create custom panels based on the specific fields they need (e.g.,
scanRows
,
returnRows
,
planCpuCosts
). Referencesadministration/management/monitoring/Monitor_and_Alert.mdintegrations/BI_integrations/Tableau_Desktop.mdintegrations/BI_integrations/Querybook.md
z
@Rocky and what about currently running queries? can I connect query detail api to grafana?
r
To view currently running queries in Grafana, you have two primary options: using the Query Detail API (REST) or using system tables (SQL). 1. Using the Query Detail API (REST) The Query Detail API provides real-time information on queries currently being processed by the FE (if the state is
RUNNING
). * Endpoint:
GET http://<FE_IP>:8030/api/query_detail
* Prerequisite: Ensure
enable_collect_query_detail_info = true
is set in your FE configuration. * Grafana Setup: 1. Install the Infinity or JSON API data source plugin in Grafana. 2. Configure the data source with your FE's IP, port (8030), and Basic Auth (StarRocks username/password). 3. In your dashboard panel, use the data source to parse the JSON response. You can filter for queries where
"state": "RUNNING"
. 2. Using Information Schema (SQL) — Recommended Since you already have a MySQL connection for AuditLoader, querying the
information_schema
is the simplest way to see active queries without extra plugins. * Table:
information_schema.warehouse_queries
(Available in v3.2+) * Grafana Query:
Copy code
sql
    SELECT
        QUERY_ID,
        STATE,
        QUERY,
        QUERY_START_TIME,
        QUERY_DURATION
    FROM information_schema.warehouse_queries
    WHERE STATE = 'RUNNING';
3. Alternative SQL Commands If you are on an older version or need broader details, you can use these commands, though they are harder to format in Grafana because they are "PROC" commands rather than standard tables: * `SHOW PROC '/current_queries'`: Shows queries on the specific FE you are connected to. * `SHOW PROC '/global_current_queries'`: Shows queries across all FEs (v3.4+). * `SHOW RUNNING QUERIES`: Best for monitoring the Query Queue status (v3.1.4+). Summary of Monitoring Options Metric Type | Method | Best For Historical | AuditLoader Table | Long-term trends, slow query analysis. Real-time (Active) |
information_schema
| Dashboards showing what's running now. Detailed Profiles | Query Detail API | Deep dives into memory/CPU cost of specific queries. Counts Only | Prometheus | Monitoring total query load/concurrency. Referencesusing_starrocks/running_queries.mdadministration/http_interface/query_detail.mdsql-reference/information_schema/warehouse_queries.mdadministration/management/resource_management/query_queues.md Referencesusing_starrocks/running_queries.mdadministration/management/resource_management/query_queues.mdsql-reference/information_schema/warehouse_queries.mdsql-reference/information_schema/information_schema.md