Grafana Integration
TraceHouse is available as a Grafana app plugin. The plugin includes the same static frontend as the standalone build, including the overview, merge tracker, query monitor and database explorer. Grafana serves the frontend as an app page.
How It Works
In standalone mode, the browser connects to ClickHouse over HTTP/HTTPS with @clickhouse/client-web. In the Grafana plugin, the browser sends each query to the Grafana backend, which executes it through the Grafana ClickHouse data source plugin (a separate plugin maintained by Grafana Labs).
Standalone: Browser ──HTTP──▶ ClickHouse
Grafana: Browser ──▶ Grafana backend ──▶ ClickHouse data source plugin ──▶ ClickHouse
Both builds use the same React UI, SQL, services from packages/core, and attribution models. They use different adapters to execute queries.
Linking From Existing Dashboards
A Grafana data link on a panel can open TraceHouse at the query, merge or point in time that the panel shows.
The link targets the TraceHouse app plugin in the Grafana instance serving the dashboard. The URL path starts with the plugin route, /a/dmkskd-tracehouse-app/, and resolves against that Grafana instance's origin. The destination page uses the current Grafana session and its user and data source permissions.
Adding a Link
- Edit the panel.
- In Data links and actions, select + Add link.
- Enter a Title and paste a URL from the recipes below.
- Turn on Open in a new tab.
- Save the dashboard.
Grafana shows the link when the user clicks a data point or line on a time series panel, or a cell on a table panel.
Linking a Point in Time
On a time series panel, ${__value.time} holds the timestamp of the clicked point, and the link passes it to TraceHouse in the th_at parameter:
/a/dmkskd-tracehouse-app/queries?status=error&th_at=${__value.time}
This link opens the Queries page filtered to the failed queries that finished between 5 minutes before and 5 minutes after the clicked point. TraceHouse opens a window rather than the exact instant because a rate panel computes each point over the interval that ends at the point's timestamp, so the queries counted in a spike finished before that timestamp, and with a rate interval of 5 minutes or less they fall inside the window.
In the following table, each URL is relative to the plugin route, /a/dmkskd-tracehouse-app.
| Panel shows | URL | Opens |
|---|---|---|
| Failed queries | /queries?status=error&th_at=${__value.time} | Failed queries, ±5 min |
| Queries over the memory limit | /queries?status=error&errorCode=241&th_at=${__value.time} | Queries that failed with MEMORY_LIMIT_EXCEEDED (241), ±5 min |
| Rejected inserts | /queries?status=error&queryKind=Insert&errorCode=252&th_at=${__value.time} | Inserts that failed with TOO_MANY_PARTS (252), ±5 min |
| Delayed inserts | /queries?queryKind=Insert&sortField=query_duration_ms&sortDir=desc&th_at=${__value.time} | Inserts, slowest first, ±5 min |
| Failed asynchronous inserts | /events?event_kind=async_insert_failure&th_at=${__value.time} | Failures from system.asynchronous_insert_log, ±5 min |
| Merges | /merges?th_at=${__value.time} | Merges, ±5 min |
| CPU, memory or query rate | /timetravel?th_at=${__value.time} | Time Travel, centered on the point |
ClickHouse delays an INSERT, rather than rejecting it, when a partition has more active parts than parts_to_delay_insert, and the delayed INSERT completes without an error. Because delayed inserts do not appear as failed queries, the delayed inserts link lists the inserts in the window ordered by duration, slowest first.
Time Travel opens with a 15-minute view centered on the point, which is the smallest of its zoom levels that shows 5 minutes on each side. To select the metric, add tt_metric=cpu or tt_metric=memory to the link, and to show only queries or only merges, add tt_ops=query or tt_ops=merge.
A panel can have more than one data link, in which case Grafana lists all of them when the user clicks a point. The Rejected Inserts panel in the example dashboard, for example, links to the rejected inserts, to merges and to Time Travel at the same point.
The Queries, Merges and Events pages write their filters to the page URL, so a link for another filter can be built by setting the filter on the page, copying the query string from the address bar and replacing its time range parameters with th_at=${__value.time}.
Link Parameters
| Parameter | Value | Default |
|---|---|---|
th_at | Point in time, as epoch milliseconds (${__value.time}) or an ISO date (2026-11-09T12:00:00Z) | |
th_pad | Time shown on each side of th_at: 1m, 15m, 1h | 5m, with a minimum of 1m. Time Travel rounds the value up to its next zoom level |
th_from, th_to | Time range, for example ${__from} and ${__to} for the dashboard's time range | |
th_ds | UID of the ClickHouse data source | The only ClickHouse data source, or the one last selected in TraceHouse |
th_cluster | Cluster name, as listed in system.clusters | The cluster configured in the plugin settings, or the detected cluster |
- When a link includes both
th_atand a range, the Queries, Merges and Events pages useth_at, and Time Travel usesth_atfor the view and the range for its time navigator. - When the page opens, TraceHouse replaces
th_at,th_pad,th_fromandth_towith the page's own time range parameters, so a URL copied from the page reflects any later change to the time range. th_dsis required only when Grafana has more than one ClickHouse data source. In a link,${datasource}references a dashboard's data source variable, withdatasourcereplaced by the variable's name. If no ClickHouse data source matches the UID, TraceHouse displays an error.th_clusteris required only when the data source has more than one cluster. TraceHouse treats an empty value as omitted and displays an error if the named cluster does not exist.
Dashboards Built on Prometheus
A dashboard built on Prometheus, such as the ClickHouse mixin, has a data source variable that refers to Prometheus and therefore cannot be used for th_ds. When Grafana has more than one ClickHouse data source, add a dashboard variable of type Data source that is limited to ClickHouse data sources, and pass it in each link as th_ds=${th_datasource}.
Prometheus series labels identify the scrape target, for example instance="ch-s1r1:9363", which may differ from the host name that ClickHouse reports, so the recipes do not filter by host. TraceHouse also does not derive th_ds or th_cluster from Prometheus labels, so when a dashboard selects one of several services or clusters, its links must set th_ds and th_cluster to match the selection.
Linking a Query
The demo stack includes the ClickHouse - Query Analysis [TraceHouse linked] dashboard, defined in infra/docker/grafana/dashboards/TraceHouse/query-analysis-linked.json. This dashboard adds a data link to the standard query analysis dashboard through a field override for the Query id field in the "Query overview" table panel:
{
"matcher": { "id": "byName", "options": "Query id" },
"properties": [
{
"id": "links",
"value": [
{
"title": "Open in TraceHouse",
"url": "/a/dmkskd-tracehouse-app/queries?qd_id=${__value.raw}&th_ds=${datasource}",
"targetBlank": true
}
]
}
]
}
Selecting the data link for a query ID opens the query detail view in the TraceHouse query monitor.
qd_id- query ID used to retrieve the query details.${__value.raw}references the raw field value of the selected table cell.
To add the link to another dashboard, edit the table panel, add a field override for the query ID column, and add a data link with the URL above.
Linking a Merge
TraceHouse identifies a merge by the database, table and output part name. The data link URL references these values from the selected table row. The panel query must read system.part_log and return database, table and part_name. The following query also returns the host, event timestamp and event type used by the optional URL parameters:
SELECT
event_time,
hostName() AS hostname,
event_type,
database,
table,
part_name,
duration_ms
FROM system.part_log
WHERE event_type = 'MergeParts'
ORDER BY event_time DESC
Configure a data link on the part_name field. ${__data.fields.<column>} references the value of another field in the selected table row:
/a/dmkskd-tracehouse-app/merges?md_db=${__data.fields.database}&md_tbl=${__data.fields.table}&md_part=${__value.raw}&md_host=${__data.fields.hostname}&md_time=${__data.fields.event_time}&md_type=${__data.fields.event_type}&th_ds=${datasource}
Selecting the data link for a part name opens the merge detail view in the TraceHouse merge tracker.
md_db,md_tbl,md_part(required) - database, table and name of the part produced by the merge.md_host(optional) - replica host name used to restrict thesystem.part_loglookup to that replica. For replicated tables, multiple replicas can record events for the same part, includingMergePartswhen a replica performs the merge andDownloadPartwhen a replica fetches the part.md_time,md_type(optional, used only withmd_host) -event_timeandevent_typeof thesystem.part_logentry. Together withmd_host, these parameters identify the event to retrieve.
Without md_host, TraceHouse returns the most recent system.part_log entry for the part across all replicas, filtered to the event types MergeParts, MutatePart, MovePart and DownloadPart. Set md_host to restrict the lookup to the replica that performed the merge.
Example Dashboards
The demo stack provisions two linked dashboards in the TraceHouse folder:
- ClickHouse - Query Analysis [TraceHouse linked] (
infra/docker/grafana/dashboards/TraceHouse/query-analysis-linked.json) links the query ID column of aquery_logtable to the query detail view. - ClickHouse - Prom-Exporter Instance [TraceHouse linked] (
infra/docker/grafana/dashboards/TraceHouse/clickhouse-mixin-linked.json) adds the point-in-time links above to the query, insert, merge, CPU and memory panels of the official ClickHouse mixin.infra/docker/grafana/scripts/link_mixin_dashboard.pygenerates it from the upstream dashboard.
Grafana Panel Export
Query Explorer exports the current query and visualization as Grafana panel JSON. The panel query, chart settings, table styling, drill-downs, links and panel metadata are generated from the SQL and its Analytics Query Language directives.
Define and test the SQL query and visualization directives in TraceHouse, then import the generated panel JSON into Grafana.
Differences from Standalone
- No connection settings - Users do not enter host, port or credentials. They select one of the ClickHouse data sources configured in Grafana.
- Grafana permissions - Access control, team permissions and credentials are managed by Grafana. A user can use a data source in TraceHouse if Grafana grants them access to it.
- No CORS proxy - The browser sends queries to the Grafana backend, not to ClickHouse, so ClickHouse does not need CORS headers.
- No separate deployment - Grafana serves the plugin's static frontend.
Cluster Selection
The data source dropdown in the TraceHouse header lists the ClickHouse data sources configured in Grafana.
After a data source is selected, TraceHouse queries system.clusters for the available clusters and their shard and replica counts. If multiple clusters are available, a cluster dropdown appears next to the data source dropdown. TraceHouse stores the cluster selection for each data source in the browser's localStorage.
With a cluster selected, queries that read system tables from all nodes use clusterAllReplicas('cluster_name', db.table). On a single node, TraceHouse queries the tables directly.
A Grafana administrator can configure a default cluster name in the plugin settings (Configuration > Plugins > TraceHouse). The configured name takes precedence over automatic cluster detection.