Getting Started
This guide will help you get ClickLens up and running with your ClickHouse database.
1. Prerequisites
Before installing ClickLens, ensure you have:
- A running ClickHouse server (version 21.8 or later recommended)
- ClickHouse HTTP interface enabled (ports 8123 for HTTP, 8443 for HTTPS)
- A ClickHouse user account with appropriate permissions
- Redis server (optional, for improved caching performance)
ClickLens uses the ClickHouse HTTP interface (ports 8123/8443). The native TCP protocol (ports 9000/9440) is NOT supported.
2. Installation
2.1. Option 1: Docker (Recommended)
The fastest way to run ClickLens is with Docker:
docker run -d \
--name clicklens \
-p 3000:3000 \
-e CLICKHOUSE_HOST=your-clickhouse-host \
-e CLICKHOUSE_PORT=8123 \
-e LENS_USER=lensuser \
-e LENS_PASSWORD=your-password \
-e SESSION_SECRET=your-32-character-secret-key-here \
-e REDIS_URL=redis://redis-host:6379 \
ghcr.io/ntk148v/clicklens:latestThen open http://localhost:3000 (opens in a new tab) in your browser.
2.2. Option 2: Docker Compose
Create a docker-compose.yml file:
services:
app:
image: ghcr.io/ntk148v/clicklens:latest
ports:
- "3000:3000"
environment:
- CLICKHOUSE_HOST=your-clickhouse-host
- CLICKHOUSE_PORT=8123
- LENS_USER=lensuser
- LENS_PASSWORD=your-password
- SESSION_SECRET=your-32-character-secret-key-here
- NODE_ENV=production
- DISABLE_SECURE_COOKIES=true
- REDIS_URL=redis://redis:6379
depends_on:
- redis
restart: unless-stopped
redis:
image: redis:7-alpine
ports:
- "6379:6379"
restart: unless-stoppedThen run:
docker-compose up -d2.3. Option 3: Local Development
For local development with Bun:
# Clone the repository
git clone https://github.com/ntk148v/clicklens.git
cd clicklens
# Install dependencies
bun install
# Copy environment file
cp env.sample .env.local
# Edit .env.local with your ClickHouse connection details
# Then start the development server
bun devThe app will be available at http://localhost:3000 (opens in a new tab).
3. Understanding the Dual Client Architecture
ClickLens uses two types of ClickHouse connections to separate metadata operations from user queries:
3.1. Lens Service User (Environment Credentials)
Configured via LENS_USER and LENS_PASSWORD environment variables. This service account is used for:
- Schema introspection and metadata queries
- System table access for monitoring features
- Permission derivation at login time
- Background operations that don't require user context
Required grants:
-- Single node
CREATE USER lensuser IDENTIFIED BY 'password';
GRANT ACCESS MANAGEMENT ON *.* TO lensuser;
GRANT SELECT ON system.* TO lensuser;
GRANT SHOW DATABASES ON *.* TO lensuser;
GRANT SHOW TABLES ON *.* TO lensuser;
GRANT SHOW COLUMNS ON *.* TO lensuser;
-- Cluster
CREATE USER lensuser ON CLUSTER cluster-name IDENTIFIED BY 'password';
GRANT ACCESS MANAGEMENT ON *.* ON CLUSTER cluster-name TO lensuser;
GRANT SELECT ON system.* ON CLUSTER cluster-name TO lensuser;
GRANT SHOW DATABASES ON *.* ON CLUSTER cluster-name TO lensuser;
GRANT SHOW TABLES ON *.* ON CLUSTER cluster-name TO lensuser;
GRANT SHOW COLUMNS ON *.* ON CLUSTER cluster-name TO lensuser;3.2. User Client (Session Credentials)
When you log in to ClickLens, your ClickHouse username and password are used directly for:
- Executing your SQL queries
- Determining your UI permissions
- All data access operations
Your permissions in ClickLens are determined by your ClickHouse user's grants and roles. ClickLens does not add or remove permissions—it simply reflects what your ClickHouse account can do.
4. Redis Configuration (Optional)
ClickLens supports optional Redis caching to improve performance for monitoring and table browsing features.
4.1. Benefits of Redis Caching
- Faster Response Times: Cached data reduces ClickHouse query load
- Improved User Experience: Instant data display for monitoring dashboards
- Reduced Resource Usage: Less load on ClickHouse server
- Better Scalability: Handles more concurrent users efficiently
4.2. What Gets Cached
- Table Explorer data (schemas, parts, merges, mutations)
- Monitoring metrics (system.metrics, system.asynchronous_metrics)
- Query analytics data
- Time-series chart data
4.3. Setting Up Redis
Docker Compose (recommended):
services:
redis:
image: redis:7-alpine
ports:
- "6379:6379"
restart: unless-stoppedLocal Development:
# Using Docker
docker run -d -p 6379:6379 redis:7-alpine
# Or install Redis locally
# Ubuntu/Debian
sudo apt-get install redis-server
# macOS
brew install redis
brew services start redis4.4. Configuration
Add the REDIS_URL environment variable to your ClickLens configuration:
# Docker
-e REDIS_URL=redis://redis:6379
# Docker Compose
- REDIS_URL=redis://redis:6379
# Local development (.env.local)
REDIS_URL=redis://localhost:6379Connection String Format:
- Basic:
redis://localhost:6379 - With password:
redis://:password@localhost:6379 - With database:
redis://localhost:6379/0 - Full example:
redis://:mypassword@redis.example.com:6379/1
Redis is completely optional. If REDIS_URL is not configured, ClickLens
will function normally without caching. Redis is recommended for production
deployments with multiple users or frequent monitoring usage.
5. ClickHouse System Tables
ClickLens relies on ClickHouse's built-in system tables to provide its features. Understanding which tables are used helps with permission planning and troubleshooting.
5.1. System Tables by Feature
| Feature | System Tables Used | Purpose |
|---|---|---|
| Monitoring Overview | system.metrics, system.asynchronous_metrics, system.events, system.query_log | Server metrics, uptime, query throughput |
| Cluster Health | system.clusters, system.replicas, system.replication_queue | Cluster topology, node status, replication state |
| Disk Usage | system.disks, system.parts | Storage capacity, compression ratios |
| Query Analytics | system.processes, system.query_log, system.query_cache | Running queries, history, cache stats |
| Table Explorer | system.tables, system.columns, system.parts, system.merges, system.mutations | Schema browsing, part information |
| Keeper/ZooKeeper | system.metrics (ZooKeeper*), system.events (ZooKeeper*) | Coordination service health |
| Logging | system.text_log, system.session_log, system.crash_log | Server and session logs |
| Settings | system.settings, system.server_settings | Configuration values |
| Time-Series Charts | system.metric_log, system.query_log | Historical metrics for graphs |
The system.metric_log table must be enabled in ClickHouse's config for
time-series graphs to work. See the ClickHouse metric_log
documentation (opens in a new tab).
5.2. Optional System Tables
Some ClickLens features depend on tables that may not exist by default:
| Table | When Created | Feature Impact |
|---|---|---|
system.text_log | Must be enabled in config | Server logs viewer |
system.session_log | Must be enabled in config | Session logs viewer |
system.crash_log | Created when crashes occur | Crash logs viewer |
system.metric_log | Must be enabled in config | Time-series monitoring charts |
system.query_log | Enabled by default | Query history and analytics |
To enable optional logging tables, add to your ClickHouse config.xml:
<clickhouse>
<!-- Enable text_log for server logs -->
<text_log>
<database>system</database>
<table>text_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</text_log>
<!-- Enable session_log for login tracking -->
<session_log>
<database>system</database>
<table>session_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</session_log>
<!-- Enable metric_log for time-series charts -->
<metric_log>
<database>system</database>
<table>metric_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
<collect_interval_milliseconds>1000</collect_interval_milliseconds>
</metric_log>
</clickhouse>6. First Login
- Navigate to http://localhost:3000 (opens in a new tab)
- Enter your ClickHouse credentials:
- Username: Your ClickHouse user
- Password: Your ClickHouse password
- Click Login
Upon successful login, you'll be taken to the Dashboard.
7. The Dashboard
The Dashboard is your starting point in ClickLens. It displays feature cards based on your permissions:
| Feature | Description | Required Permission |
|---|---|---|
| SQL Console | Execute queries with syntax highlighting and auto-completion | canExecuteQueries |
| Table Explorer | Browse databases, tables, and parts | canBrowseTables |
| Query Monitoring | Monitor running queries and view history | canViewProcesses |
| Cluster Health | CPU, memory, merges, and Keeper status | canViewCluster |
| Access Control | Manage users and roles | canManageUsers |
| Logging | View system and query logs | canViewCluster |
Feature cards are dynamically shown or hidden based on your ClickHouse user's permissions. If you're missing expected features, check your ClickHouse grants.
8. Permission System Overview
ClickLens implements a sophisticated permission derivation model that leverages ClickHouse's native RBAC system.
8.1. How Permissions Work
When you log in:
- ClickLens authenticates against your ClickHouse server
- Your grants are queried from
system.grants(via Lens Client) - Grants are mapped to UI permission flags
- The UI shows only what you have permission to access
8.2. Permission Flags
| Permission Flag | Derived From | Feature Enabled |
|---|---|---|
canManageUsers | ACCESS MANAGEMENT grant | User/Role Management |
canViewProcesses | SELECT ON system.processes | Query Monitoring |
canKillQueries | KILL QUERY grant | Query Termination |
canViewCluster | SELECT ON system.clusters | Cluster Monitoring |
canBrowseTables | SHOW TABLES grant | Table Explorer |
canExecuteQueries | SELECT on any database | SQL Console |
canDiscover | SHOW TABLES + SELECT | Discover Feature |
canViewSettings | SELECT ON system.settings | Settings Module |
canViewServerLogs | SELECT ON system.text_log | Server Logs Tab |
canViewSessionLogs | SELECT ON system.session_log | Session Logs Tab |
canViewCrashLogs | SELECT ON system.crash_log | Crash Logs Tab |
8.3. Feature Roles
ClickLens defines 6 predefined ClickHouse roles that bundle common permission sets:
| Role | Purpose | Required Grants |
|---|---|---|
clicklens_table_explorer | Browse schemas | SHOW DATABASES, SHOW TABLES, SELECT ON system.{tables,columns,parts,replicas,mutations,merges} |
clicklens_query_monitor | Monitor queries | KILL QUERY, SELECT ON system.{processes,query_log,query_cache} |
clicklens_cluster_monitor | Monitor cluster | SELECT ON system.{clusters,replicas,metrics,events,disks,replication_queue,asynchronous_metrics} |
clicklens_user_admin | Manage users/roles | ACCESS MANAGEMENT ON *.* |
clicklens_table_admin | DDL operations | TRUNCATE, OPTIMIZE ON *.* |
clicklens_settings_admin | View configuration | SELECT ON system.{settings,server_settings} |
XML-Configured Users (e.g., default user): Some users receive access via
users.xml instead of SQL grants. Since these privileges don't appear in
system.grants, ClickLens intelligently falls back to user-credential probes
(running SHOW GRANTS and probing system.tables with the user's
credentials) to accurately determine access.
9. Troubleshooting
9.1. Connection Issues
Problem: Cannot connect to ClickHouse
Solutions:
- Verify
CLICKHOUSE_HOSTandCLICKHOUSE_PORTare correct - Ensure the HTTP interface is enabled (not just native protocol)
- Check firewall rules
- Verify ClickHouse is running:
curl http://localhost:8123/ping
9.2. Permission Issues
Problem: Features not showing on dashboard
Solutions:
- Check your ClickHouse grants:
SHOW GRANTS FOR current_user() - Ensure required system tables are accessible
- Verify the Lens service user has proper permissions
- Check if you're using XML-configured users (see note above)
9.3. Session Issues
Problem: Frequent session expirations
Solutions:
- Ensure
SESSION_SECRETis consistent across restarts - Check cookie settings if behind a proxy (
DISABLE_SECURE_COOKIES) - Verify the secret is at least 32 characters
9.4. SSL Certificate Errors
Problem: SSL certificate verification failed
Solutions:
- Set
CLICKHOUSE_VERIFY=falsefor self-signed certificates - Or install the CA certificate in the container
- Ensure
CLICKHOUSE_SECURE=trueif using HTTPS
9.5. Redis Connection Issues
Problem: Redis caching not working
Solutions:
- Verify Redis is running:
redis-cli pingshould returnPONG - Check
REDIS_URLenvironment variable is correct - Ensure Redis is accessible from ClickLens container (network connectivity)
- Verify Redis port (default 6379) is not blocked by firewall
- Check Redis logs for connection errors
Redis is optional. If Redis is unavailable, ClickLens will continue to function
normally without caching. You can temporarily disable Redis by removing the
REDIS_URL environment variable.
10. Next Steps
- Explore the Features guide to learn about each module
- Read about Deployment for production configuration
- Check the Architecture documentation for technical details