Altinity Grafana datasource plugin for ClickHouse®
Altinity Grafana datasource plugin for ClickHouse®
Altinity ClickHouse datasource plugin provides a support for ClickHouse as a backend database.
Initially plugin developed by Vertamedia, maintaned by Altinity since 2020.
Because we added output_format_json_quote_64bit_integers=1 to any browser request from plugin,
if your user which you use for connection have readonly=1, change it to readonly=2, for example
/etc/clickhouse-server/users.d/readonly.xml
2
New ClickHouse version change default behavior for output_format_json_quote_64bit_integers=0,
which not allows to read generated JSON in JavaScript, look details in https://github.com/ClickHouse/ClickHouse/issues/86553
To properly works old version Altinity clickhouse datasource plugin for Grafana use following config
/etc/clickhouse-server/users.d/output_format_json_quote_64bit_integers.xml
1
Old versions of Altinity ClickHouse datasource plugin for Grafana written in Angular. So you can watch warning like
Angular plugin
This data source plugin uses a deprecated, legacy platform based on AngularJS and will stop working in future releases of Grafana.
Don't worry about warning message, plugin will still working until Grafana 11 will release, after it upgrade to Altinity ClickHouse datasource plugin for Grafana to 3.x version is required.
When 2.0.x and 2.1.x vertamedia-clickhouse-grafana plugin versions released Grafana team didn't provide worked signing method for community plugins. Current sign process describe on grafana.com
so, for properly setup 2.0.x and 2.1.x plugins you need change configuration option
[plugins]
allow_loading_unsigned_plugins=vertamedia-clickhouse-datasource
or setup environment variable
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=vertamedia-clickhouse-datasource
You can install plugin from grafana.com
OR
Copy files to your Grafana plugin directory. Restart Grafana, check data sources list at Configuration -> Datasources -> New, choose ClickHouse option.
Page configuration is standard
There is a small feature - ClickHouse treats HTTP Basic Authentication credentials as a database user and will try to run queries using its name.
Using of CHProxy will bring additional features:
HTTPS access to ClickHouse as shown here
to provide secure access.Grafana as shown here
to prevent ClickHouse overloading from Grafana.CHProxy allows queueing requests and execute them sequentially.
To learn more - read about params max_queue_size and max_queue_time at CHProxy page.Caching will protect ClickHouse from excessive refreshes and will be optimal option for popular dashboards.
Hint - if you need to cache requests like
last 24hwhere timestamp changes constantly then try to useRoundoption atRaw Editor
Query setup interface:
First row FROM contains two options: database and table. Table values depends on a selected database.
Next rows contains selectors for time filtering:
Column timestamp time
Timestamp column Date column
Timestmap columnare required for time-based macros and functions because all analytics based on these values. Plugin will try to detect Date, Date32 column automatically
Button Go to Query is just a toggler to Raw SQL Editor
Raw Editor allows custom SQL queries to be written:
Raw Editor allows typing queries, get info about functions and macros, format queries as Clickhouse do. To Execute query on server press "Run Query" or just leave focus from SQL editor textarea.
Under the Editor you can find options which allows setup rounding, time column step
and Add metadata to SQL query which allows know which dashboard and user produce workload to your ClickHouse server.
Press Show Generated SQL for see a raw query (all macros and functions have already been replaced) which will be sent directly to ClickHouse.
Plugin supports the following marcos:
Column:Date value from Query BuilderColumn:DateTime or Column:TimeStamp value from Query Builder$column argument. Use it in queries or query variables as ...WHERE $timeFilterColumn($column)... or ...WHERE $timeFilterColumn(created_at)....A description of macros is available by typing their names in Raw Editor
Functions are just templates of SQL queries, and you can check the final query at Raw SQL Editor mode. If you need some additional complexity - just copy raw sql into Raw Editor and make according changes. Remember that macros are still available to use.
There are some limits in function use because of poor query analysis:
Plugin supports the following functions:
Example usage:
$rate(countIf(Type = 200) AS good, countIf(Type != 200) AS bad) FROM requests
Query will be transformed into:
…
sql $columns( Size, sum(Items) Items) FROM some_table
// It is also possible to use query without macros
### Worldmap panel ([https://github.com/grafana/worldmap-panel](https://github.com/grafana/worldmap-panel))
If you have a table with country/city codes:
```sql
SELECT
1,
Country AS c,
sum(Requests) AS Reqs
FROM requests
GLOBAL ANY INNER JOIN
(
SELECT Country, CountryCode
FROM countries
) USING (CountryCode)
WHERE $timeFilter
GROUP BY
c
ORDER BY Reqs DESC
…
sql
SELECT database, table, name, type FROM system.columns WHERE table='myTable' ORDER BY database, table
That should help to control data fetching by ad-hoc queries.
To use time range dependent macros like $from and $to in your query the refresh mode of the template variable needs to be set to On Time Range Change.
SELECT ClientID FROM events WHERE EventTime > toDateTime($from) AND EventTime if(addressToSymbol(x) != '', demangle(addressToSymbol(x)), 'unknown') , trace) AS label
WHERE trace_type='Real' AND $timeFilter
GROUP BY level, label, trace
ORDER BY trace, level
…
sql
SELECT
trace_id AS traceID,
span_id AS spanID,
operation_name AS operationName,
parent_span_id AS parentSpanID,
'clickhouse' AS serviceName,
intDiv(finish_time_us - start_time_us, 1000) AS duration,
intDiv(start_time_us,1000) AS startTime,
attribute AS tags,
map('hostName',hostname) AS serviceTags
FROM
system.opentelemetry_span_log
WHERE $timeFilter
ORDER BY traceID, startTime
It’s now possible to configure datasources using config files with Grafana’s provisioning system. You can read more about how it works and all the settings you can set for datasources on the provisioning docs page.
Here are some provisioning example:
apiVersion: 1
datasources:
- name: Clickhouse
type: vertamedia-clickhouse-datasource
access: proxy
url: http://localhost:8123
# enable/disable basic auth
basicAuth: false
# basic auth username
basicAuthUser: "default"
# enable/disable with credentials headers
withCredentials: false
# mark as default datasource. Max one per org
isDefault: false
# fields that will be converted to json and stored in json_data
jsonData:
# enable/disable sending 'add_http_cors_header=1' parameter
addCorsHeader: false
# enable/disable using POST method for sending queries
usePOST: false
# enable/disable using Accept-Encoding header in each request
useCompression: false
# compression type allowed values: gzip, zstd, br, deflate
compressionType: ""
# default database name
defaultDatabase: ""
# enable/disable tls authorization
tlsAuth: false
# enable/disable tls authorization with custom ca
tlsAuthWithCACert: false
# enable/disable authorization with X-ClickHouse-* headers
useYandexCloudAuthorization: false
# X-ClickHouse-Key header value for authorization
xHeaderUser: ""
# the same value as url when `useYandexCloudAuthorization: true`
# @todo remove this workaround when merge https://github.com/grafana/grafana/pull/80858
dataSourceUrl: "http://localhost:8123"
secureJsonData:
# X-ClickHouse-User header value for authorization
xHeaderKey: ""
# basic auth password
basicAuthPassword: ""
# custom certificate authority for TLS https connection, base64 encoded
tlsCACert: ""
# custom client certificate for TLS https connection, base64 encoded
tlsClientCert: ""
# custom client
No open issues yet, or sync has not completed.