The simple Next.js dashboard that relies on system.*
tables to help monitor and provide an overview of your ClickHouse cluster.
Features:
- Query monitor: current queries, query history, query resources (memory, parts read, file_open, ...), most expensive queries, most used tables or columns, etc.
- Cluster monitor: total memory/CPU usage, distributed queue, global settings, mergetree settings, metrics, etc.
- Tables and parts information: size, row count, compression, part size, etc., at the column level detail.
- Useful tools: Zookeeper data exploration, query EXPLAIN, kill queries, etc.
- Visualization metric charts: queries and resource usage, number of merges/mutation, merge performance, query performance, etc.
Demo (The ClickHouse server running on my homelab so can be slow sometimes):
Documentation:
Screenshots:
To get the project up and running on your local machine, follow these steps:
-
Clone the repository
-
Install dependencies using
npm install
oryarn install
-
Create a
.env.local
file by copying the.env.example
file and filling in the required environment variables:CLICKHOUSE_HOST
: ClickHouse host(s), for examplehttp://localhost:8123
orhttp://ch-1:8123,http://ch-2:8123
CLICKHOUSE_NAME
: (Optional) Name of ClickHouse instance, must match the number of hosts inCLICKHOUSE_HOST
, for examplelocalhost
orch-1,ch-2
.CLICKHOUSE_USER
: ClickHouse user with permission to query thesystem
database.CLICKHOUSE_PASSWORD
: ClickHouse password for the specified user.CLICKHOUSE_MAX_EXECUTION_TIME
:max_execution_time
timeout in seconds. Default is10
.CLICKHOUSE_TZ
: ClickHouse server timezone. Default:''
.NEXT_QUERY_CACHE_TTL
: TTL ofunstable_cache
- cache the results of most charts to speed up and reuse them across multiple requests. Default:86400
.NEXT_PUBLIC_LOGO
: (Optional) HTTP path to logo image.EVENTS_TABLE_NAME
: The table name for storing dashboard self-tracking events. Default:system.monitoring_events
-
Run the development server with
npm run dev
oryarn dev
-
Open http://localhost:3000 in your browser to see the dashboard.
Suggested role for "monitoring" user must have these privileges on system
database:
# File: users.d/monitoring_role.xml
<clickhouse>
<users>
<monitoring>
<password><!-- define password here --></password>
<profile>monitoring_profile</profile>
<networks><ip>::/0</ip></networks>
<grants>
<query>GRANT monitoring_role</query>
</grants>
</monitoring>
</users>
<roles>
<monitoring_role>
<grants>
<query>REVOKE ALL ON *.*</query>
<query>GRANT SELECT,SHOW,dictGet,REMOTE ON *.*</query>
<query>GRANT SELECT,INSERT,ALTER,CREATE,DROP,TRUNCATE,OPTIMIZE,SHOW,dictGet ON system.*</query>
<query>GRANT CREATE TEMPORARY TABLE ON *.*</query>
</grants>
</monitoring_role>
</roles>
</clickhouse>
CREATE TEMPORARY TABLE
is needed because the UI using FROM merge(system, '^query_log')
allows retrieving all the data from old tables that were renamed during the upgrade.
# File: users.d/monitoring_profile.xml
<clickhouse>
<profiles>
<monitoring_profile>
<allow_experimental_analyzer>1</allow_experimental_analyzer>
<!-- Optional: query cache to avoid hit too much queries on database -->
<use_query_cache>1</use_query_cache>
<query_cache_ttl>50</query_cache_ttl>
<query_cache_max_entries>0</query_cache_max_entries>
<query_cache_system_table_handling>save</query_cache_system_table_handling>
<query_cache_nondeterministic_function_handling>save</query_cache_nondeterministic_function_handling>
</monitoring_profile>
</profiles>
</clickhouse>
For easy deployment, use the Vercel Platform, created by the makers of Next.js. Refer to the Next.js deployment documentation for more details.
Using the latest image here: https://github.com/duyet/clickhouse-monitoring/pkgs/container/clickhouse-monitoring
docker run -it \
-e CLICKHOUSE_HOST='http://localhost' \
-e CLICKHOUSE_USER='default' \
-e CLICKHOUSE_PASSWORD='' \
-e CLICKHOUSE_TZ='Asia/Ho_Chi_Minh' \
-e CLICKHOUSE_MAX_EXECUTION_TIME='15' \
-e NEXT_QUERY_CACHE_TTL='86400' \
--name clickhouse-monitoring \
ghcr.io/duyet/clickhouse-monitoring:main
Using the latest helm chart here: https://github.com/duyet/charts/tree/master/clickhouse-monitoring
helm repo add duyet https://duyet.github.io/charts
cat <<EOF >> values.yaml
env:
- name: CLICKHOUSE_HOST
value: http://localhost:8123
- name: CLICKHOUSE_USER
value: default
- name: CLICKHOUSE_PASSWORD
value: ''
- name: CLICKHOUSE_TZ
value: 'Asia/Ho_Chi_Minh'
- name: CLICKHOUSE_MAX_EXECUTION_TIME
value: '15'
- name: NEXT_QUERY_CACHE_TTL
value: '86400'
EOF
helm install -f values.yaml clickhouse-monitoring-release duyet/clickhouse-monitoring
Feedback and contributions are welcome! Feel free to open issues or submit pull requests.
See LICENSE.