• Stars
    star
    101
  • Rank 325,956 (Top 7 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Grafana Plugin for ClickHouse

Official ClickHouse data source for Grafana

The ClickHouse data source plugin allows you to query and visualize ClickHouse data in Grafana.

Grafana Dashboard Screenshot - Query Analysis Grafana Dashboard Screenshot - Data Analysis

Version compatibility

Users on Grafana v9.x and higher of Grafana can use v4. Users on Grafana v8.x are encouraged to continue using v2.2.0 of the plugin.

* As of 2.0 this plugin will only support ad hoc filters when using ClickHouse 22.7+

Installation

For detailed instructions on how to install the plugin on Grafana Cloud or locally, please checkout the Plugin installation docs.

Configuration

ClickHouse user for the data source

Set up an ClickHouse user account with readonly permission and access to databases and tables you want to query. Please note that Grafana does not validate that queries are safe. Queries can contain any SQL statement. For example, statements like ALTER TABLE system.users DELETE WHERE name='sadUser' and DROP TABLE sadTable; would be executed.

To configure a readonly user, follow these steps:

  1. Create a readonly user profile following the Creating Users and Roles in ClickHouse guide.
  2. Ensure the readonly user has enough permission to modify the max_execution_time setting required by the underlying clickhouse-go client.
  3. If you're using a public Clickhouse instance, it's not recommended to set readonly=2 in the readonly profile. Instead, leave readonly=1 and set the constraint type of max_execution_time to changeable_in_readonly to allow modification of this setting.

ClickHouse protocol support

The plugin supports both Native (default) and HTTP transport protocols. This can be enabled in the configuration via the protocol configuration parameter. Both protocols exchange data with ClickHouse using optimized native format.

Note that the default ports for HTTP/S and Native differ:

  • HTTP - 8123
  • HTTPS - 8443
  • Native - 9000
  • Native with TLS - 9440

Manual configuration via UI

Once the plugin is installed on your Grafana instance, follow these instructions to add a new ClickHouse data source, and enter configuration options.

With a configuration file

It is possible to configure data sources using configuration files with Grafanaโ€™s provisioning system. To read about how it works, refer to Provisioning Grafana data sources.

Here are some provisioning examples for this data source using basic authentication:

apiVersion: 1
datasources:
  - name: ClickHouse
    type: grafana-clickhouse-datasource
    jsonData:
      defaultDatabase: database
      port: 9000
      host: localhost
      username: username
      tlsSkipVerify: false
      # tlsAuth: <bool>
      # tlsAuthWithCACert: <bool>
      # secure: <bool>
      # dialTimeout: <seconds>
      # queryTimeout: <seconds>
      # protocol: <native|http>
      # defaultTable: <string>
      # httpHeaders:
      # - name: X-Example-Header
      #   secure: false
      #   value: <string>
      # - name: Authorization
      #   secure: true
      # logs:
      #   defaultDatabase: <string>
      #   defaultTable: <string>
      #   otelEnabled: <bool>
      #   otelVersion: <string>
      #   timeColumn: <string>
      #   ...Column: <string>
      # traces:
      #   defaultDatabase: <string>
      #   defaultTable: <string>
      #   otelEnabled: <bool>
      #   otelVersion: <string>
      #   durationUnit: <seconds|milliseconds|microseconds|nanoseconds>
      #   traceIdColumn: <string>
      #   ...Column: <string>
    secureJsonData:
      password: password
      # tlsCACert: <string>
      # tlsClientCert: <string>
      # tlsClientKey: <string>
      # secureHttpHeaders.Authorization: <string>

Building queries

Queries can be built using the raw SQL editor or the query builder. Queries can contain macros which simplify syntax and allow for dynamic SQL generation.

Time series

Time series visualization options are selectable after adding a datetime field type to your query. This field will be used as the timestamp. You can select time series visualizations using the visualization options. Grafana interprets timestamp rows without explicit time zone as UTC. Any column except time is treated as a value column.

Multi-line time series

To create multi-line time series, the query must return at least 3 fields in the following order:

  • field 1: datetime field with an alias of time
  • field 2: value to group by
  • field 3+: the metric values

For example:

SELECT log_time AS time, machine_group, avg(disk_free) AS avg_disk_free
FROM mgbench.logs1
GROUP BY machine_group, log_time
ORDER BY log_time

Tables

Table visualizations will always be available for any valid ClickHouse query.

Visualizing logs with the Logs Panel

To use the Logs panel your query must return a timestamp and string values. To default to the logs visualization in Explore mode, set the timestamp alias to log_time.

For example:

SELECT log_time AS log_time, machine_group, toString(avg(disk_free)) AS avg_disk_free
FROM logs1
GROUP BY machine_group, log_time
ORDER BY log_time

To force rendering as logs, in absence of a log_time column, set the Format to Logs (available from 2.2.0).

Visualizing traces with the Traces Panel

Ensure your data meets the requirements of the traces panel. This applies if using the visualization or Explore view.

Set the Format to Trace when constructing the query (available from 2.2.0).

If using the Open Telemetry Collector and ClickHouse exporter, the following query produces the required column names (these are case sensitive):

SELECT
    TraceId AS traceID,
    SpanId AS spanID,
    SpanName AS operationName,
    ParentSpanId AS parentSpanID,
    ServiceName AS serviceName,
    Duration / 1000000 AS duration,
    Timestamp AS startTime,
    arrayMap(key -> map('key', key, 'value', SpanAttributes[key]), mapKeys(SpanAttributes)) AS tags,
    arrayMap(key -> map('key', key, 'value', ResourceAttributes[key]), mapKeys(ResourceAttributes)) AS serviceTags
FROM otel.otel_traces
WHERE TraceId = '61d489320c01243966700e172ab37081'
ORDER BY startTime ASC

Macros

To simplify syntax and to allow for dynamic parts, like date range filters, the query can contain macros.

Here is an example of a query with a macro that will use Grafana's time filter:

SELECT date_time, data_stuff
FROM test_data
WHERE $__timeFilter(date_time)
Macro Description Output example
$__dateFilter(columnName) Replaced by a conditional that filters the data (using the provided column) based on the date range of the panel date >= toDate('2022-10-21') AND date <= toDate('2022-10-23')
$__timeFilter(columnName) Replaced by a conditional that filters the data (using the provided column) based on the time range of the panel in seconds time >= toDateTime(1415792726) AND time <= toDateTime(1447328726)
$__timeFilter_ms(columnName) Replaced by a conditional that filters the data (using the provided column) based on the time range of the panel in milliseconds time >= fromUnixTimestamp64Milli(1415792726123) AND time <= fromUnixTimestamp64Milli(1447328726456)
$__fromTime Replaced by the starting time of the range of the panel casted to DateTime toDateTime(1415792726)
$__toTime Replaced by the ending time of the range of the panel casted to DateTime toDateTime(1447328726)
$__fromTime_ms Replaced by the starting time of the range of the panel casted to DateTime64(3) fromUnixTimestamp64Milli(1415792726123)
$__toTime_ms Replaced by the ending time of the range of the panel casted to DateTime64(3) fromUnixTimestamp64Milli(1447328726456)
$__interval_s Replaced by the interval in seconds 20
$__timeInterval(columnName) Replaced by a function calculating the interval based on window size in seconds, useful when grouping toStartOfInterval(toDateTime(column), INTERVAL 20 second)
$__timeInterval_ms(columnName) Replaced by a function calculating the interval based on window size in milliseconds, useful when grouping toStartOfInterval(toDateTime64(column, 3), INTERVAL 20 millisecond)
$__conditionalAll(condition, $templateVar) Replaced by the first parameter when the template variable in the second parameter does not select every value. Replaced by the 1=1 when the template variable selects every value. condition or 1=1

The plugin also supports notation using braces {}. Use this notation when queries are needed inside parameters.

Templates and variables

To add a new ClickHouse query variable, refer to Add a query variable.

After creating a variable, you can use it in your ClickHouse queries by using Variable syntax. For more information about variables, refer to Templates and variables.

Importing dashboards for ClickHouse

Follow these instructions to import a dashboard.

You can also find available, pre-made dashboards by navigating to the data sources configuration page, selecting the ClickHouse data source and clicking on the Dashboards tab.

We distribute the following dashboards with the plugin. These are aimed at assisting with support analysis of a ClickHouse cluster and do not rely on external datasets. The querying user requires access to the system database.

  1. Cluster Analysis - an overview of configured clusters, merges, mutations and data replication.
  2. Data Analysis - an overview of current databases and tables, including their respective sizes, partitions and parts.
  3. Query Analysis - an analysis of queries by type, performance and resource consumption.

Ad Hoc Filters

Ad hoc filters are only supported with version 22.7+ of ClickHouse.

Ad hoc filters allow you to add key/value filters that are automatically added to all metric queries that use the specified data source, without being explicitly used in queries.

By default, Ad Hoc filters will be populated with all Tables and Columns. If you have a default database defined in the Datasource settings, all Tables from that database will be used to populate the filters. As this could be slow/expensive, you can introduce a second variable to allow limiting the Ad Hoc filters. It should be a constant type named clickhouse_adhoc_query and can contain: a comma delimited list of databases, just one database, or a database.table combination to show only columns for a single table.

For more information on Ad Hoc filters, check the Grafana docs

Using a query for Ad Hoc filters

The second clickhouse_adhoc_query also allows any valid Clickhouse query. The query results will be used to populate your ad-hoc filter's selectable filters. You may choose to hide this variable from view as it serves no further purpose.

For example, if clickhouse_adhoc_query is set to SELECT DISTINCT machine_name FROM mgbench.logs1 you would be able to select which machine names are filtered for in the dashboard.

Learn more

More Repositories

1

grafana

The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
TypeScript
60,280
star
2

k6

A modern load testing tool, using Go and JavaScript - https://k6.io
Go
22,905
star
3

loki

Like Prometheus, but for logs.
Go
22,069
star
4

pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
C
9,361
star
5

mimir

Grafana Mimir provides horizontally scalable, highly available, multi-tenant, long-term storage for Prometheus.
Go
3,634
star
6

tempo

Grafana Tempo is a high volume, minimal dependency distributed tracing backend.
Go
3,561
star
7

oncall

Developer-friendly incident response with brilliant Slack integration
Python
3,223
star
8

tanka

Flexible, reusable and concise configuration for Kubernetes
Go
2,235
star
9

phlare

๐Ÿ”ฅ horizontally-scalable, highly-available, multi-tenant continuous profiling aggregation system
Go
2,059
star
10

grafana-zabbix

Zabbix plugin for Grafana dashboard
TypeScript
2,020
star
11

agent

Vendor-neutral programmable observability pipelines.
Go
1,544
star
12

helm-charts

Smarty
1,494
star
13

grafonnet-lib

Jsonnet library for generating Grafana dashboard files.
Jsonnet
1,079
star
14

beyla

eBPF-based autoinstrumentation of HTTP and HTTPS services
C
1,032
star
15

grafana-operator

An operator for Grafana that installs and manages Grafana instances, Dashboards and Datasources through Kubernetes/OpenShift CRs
Go
756
star
16

alloy

OpenTelemetry Collector distribution with programmable pipelines
Go
711
star
17

grafana-docker

Grafana docker container
Shell
638
star
18

metrictank

metrics2.0 based, multi-tenant timeseries store for Graphite and friends.
Go
623
star
19

faro-web-sdk

The Grafana Faro Web SDK, part of the Grafana Faro project, is a highly configurable web SDK for real user monitoring (RUM) that instruments browser frontend applications to capture observability signals. Frontend telemetry can then be correlated with backend and infrastructure data for full-stack observability.
TypeScript
623
star
20

grafana-infinity-datasource

CSV, JSON, GraphQL, XML and HTML datasource for grafana.
TypeScript
591
star
21

jsonnet-libs

Grafana Labs' Jsonnet libraries
Jsonnet
516
star
22

k6-operator

An operator for running distributed k6 tests.
Go
506
star
23

simple-json-datasource

Datasource that sends generic http requests to give url
JavaScript
502
star
24

awesome-k6

A curated list of awesome tools, content and projects using k6
493
star
25

carbon-relay-ng

Fast carbon relay+aggregator with admin interfaces for making changes online - production ready
Go
455
star
26

grizzly

A utility for managing Jsonnet dashboards against the Grafana API
Go
424
star
27

terraform-provider-grafana

Terraform Grafana provider
Go
391
star
28

grafana-image-renderer

A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)
TypeScript
335
star
29

dskit

Distributed systems kit
Go
316
star
30

grafana-kiosk

Kiosk Utility for Grafana
Go
314
star
31

xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
Go
310
star
32

worldmap-panel

Worldmap panel plugin for Grafana 3.0 that can be overlaid with circles for data points.
JavaScript
301
star
33

postman-to-k6

Converts Postman collections to k6 script code
JavaScript
286
star
34

xk6-dashboard

A k6 extension that makes k6 metrics available on a web-based dashboard.
HTML
278
star
35

grafana-json-datasource

A data source plugin for loading JSON APIs into Grafana.
TypeScript
261
star
36

k6-learn

JavaScript
255
star
37

k6-template-typescript

Template to use TypeScript with k6
TypeScript
250
star
38

grafonnet

Jsonnet library for generating Grafana dashboards.
Jsonnet
229
star
39

dashboard-linter

A tool to lint Grafana dashboards
Go
187
star
40

thema

A CUE-based framework for portable, evolvable schema
Go
185
star
41

tns

Observability Demo App
Jsonnet
185
star
42

intro-to-mltp

Introduction to Metrics, Logs, Traces and Profiles session companion code.
JavaScript
181
star
43

strava-datasource

Strava datasource for Grafana dashboard
TypeScript
171
star
44

xk6

Build k6 with extensions
Go
169
star
45

github-datasource

Grafana data source plugin using the Github API to retrieve and visualize Github data.
Go
169
star
46

grafana-plugin-sdk-go

A Go SDK for building backend plugins for Grafana
Go
165
star
47

jsonnet-language-server

A Language Server Protocol (LSP) server for Jsonnet (https://jsonnet.org)
Go
154
star
48

grafana-plugin-examples

Shell
152
star
49

django-saml2-auth

Django SAML2 Authentication Made Easy. Easily integrate with SAML2 SSO identity providers like Okta, Azure AD and others.
Python
151
star
50

cortex-tools

If you're using this tool with Grafana Mimir, please switch to "mimirtool" instead: https://github.com/grafana/mimir
Go
150
star
51

piechart-panel

Pie Chart Panel Plugin
JavaScript
150
star
52

grafana-plugin-repository

The plugin repository for plugins that are published on grafana.com.
JavaScript
147
star
53

mqtt-datasource

MQTT Datasource for Grafana allows streaming data from any MQTT broker running either locally or remotely.
Go
143
star
54

xk6-output-prometheus-remote

k6 extension to output real-time test metrics using Prometheus Remote Write.
Go
139
star
55

scribe

A tool for building elaborate CI pipelines using a familiar programming language
Go
124
star
56

kubernetes-diff-logger

Logs updates to Kubernetes Objects for storing and querying with Loki
Go
122
star
57

pyroscope-rs

Pyroscope Profiler for Rust. Profile your Rust applications.
Rust
119
star
58

synthetic-monitoring-agent

Synthetic Monitoring Agent
Go
118
star
59

har-to-k6

JSON config representation of K6 script
JavaScript
114
star
60

scenes

Build Grafana dashboards directly in your Grafana app plugins.
TypeScript
114
star
61

faro

Grafana Faro is a project for frontend application observability. It includes a highly configurable web SDK that instruments browser frontend applications to capture observability signals.
113
star
62

google-sheets-datasource

Load Google Sheets in grafana
Go
112
star
63

tutorials

A series of tutorials for helping you make the most out of Grafana.
Makefile
109
star
64

synthetic-monitoring-app

Synthetic Monitoring frontend application
TypeScript
107
star
65

grafana-api-golang-client

Grafana HTTP API Client for Go
Go
105
star
66

k6-action

k6 is now available as a GitHub Action
JavaScript
101
star
67

k8s-monitoring-helm

Shell
96
star
68

cuetsy

Experimental CUE->TypeScript exporter
Go
96
star
69

rollout-operator

Kubernetes Rollout Operator
Go
96
star
70

azure-monitor-datasource

Grafana data source for Azure Monitor/Application Insights (deprecated - now included in core Grafana)
TypeScript
92
star
71

dashboard-spec

Go
91
star
72

clock-panel

Clock Panel Plugin for Grafana
TypeScript
88
star
73

grafana-polystat-panel

D3-Based hexagon layout multi-stat panel
TypeScript
86
star
74

docker-otel-lgtm

Dockerfile
82
star
75

k6-docs

The k6 documentation website.
JavaScript
80
star
76

xk6-disruptor

Extension for injecting faults into k6 tests
Go
80
star
77

k6-template-es6

Template using Webpack and Babel to enable ES6 features in k6 tests
JavaScript
77
star
78

cortex-jsonnet

Deprecated: see https://github.com/grafana/mimir/tree/main/operations/mimir instead
Jsonnet
74
star
79

doom-datasource

Hackathon project
C
71
star
80

tutorial-environment

Environment for tutorial excercises
Go
70
star
81

pyroscope-go

This is the golang client integration for Pyroscope
Go
69
star
82

grafana-ansible-collection

grafana.grafana Ansible collection provides modules and roles for managing various resources on Grafana Cloud and roles to manage and deploy Grafana Agent and Grafana
Python
69
star
83

database-migrator

Code to export grafana.db (sqlite) to MySQL-compatible SQL file, to assist in migration of Grafana data to MySQL-compatible DB.
Shell
67
star
84

grafana-csv-datasource

A data source for loading CSV data into Grafana.
TypeScript
67
star
85

mimir-proxies

Proxies to help you ingest your metrics into Grafana Mimir.
Go
65
star
86

pyroscope-java

pyroscope java integration
Java
65
star
87

otel-profiling-go

Open Telemetry integration for Grafana Pyroscope and tracing solutions such as Grafana Tempo, Honeycomb, or Jaeger
Go
65
star
88

memo

easily save grafana annotations from slack mentions and the cli
Go
65
star
89

JPProf

Go Pprof but for Java runtime.
Java
65
star
90

grafana-starter-panel

A starter for Grafana panel plugins
TypeScript
65
star
91

xk6-sql

k6 extension to load test RDBMSs (PostgreSQL, MySQL, MS SQL and SQLite3)
Go
64
star
92

vscode-jsonnet

Full code support (formatting, highlighting, navigation, etc) for Jsonnet
JavaScript
64
star
93

jmeter-to-k6

Converts JMeter .jmx files to k6 JS code
JavaScript
63
star
94

xk6-distributed-tracing

A k6 extension for distributed tracing.
Go
62
star
95

github-to-es

GitHub Analytics With Elasticsearch And Grafana
JavaScript
54
star
96

opcua-datasource

An OPC UA datasource for reading from OPC UA servers (DA/HDA/AE) into Grafana directly
CSS
54
star
97

grafana-plugin-sdk-rust

Grafana Plugin SDK for Rust
Rust
53
star
98

xk6-kubernetes

Client extension for interacting with Kubernetes clusters from your k6 tests.
Go
52
star
99

regexp

Faster version of the Go regexp package
Go
51
star
100

influxdb-flux-datasource

Grafana datasource plugin for Flux (InfluxDB)
Go
51
star