Getting Started

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:latest

Then 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-stopped

Then run:

docker-compose up -d

2.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 dev

The 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-stopped

Local 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 redis

4.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:6379

Connection 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

FeatureSystem Tables UsedPurpose
Monitoring Overviewsystem.metrics, system.asynchronous_metrics, system.events, system.query_logServer metrics, uptime, query throughput
Cluster Healthsystem.clusters, system.replicas, system.replication_queueCluster topology, node status, replication state
Disk Usagesystem.disks, system.partsStorage capacity, compression ratios
Query Analyticssystem.processes, system.query_log, system.query_cacheRunning queries, history, cache stats
Table Explorersystem.tables, system.columns, system.parts, system.merges, system.mutationsSchema browsing, part information
Keeper/ZooKeepersystem.metrics (ZooKeeper*), system.events (ZooKeeper*)Coordination service health
Loggingsystem.text_log, system.session_log, system.crash_logServer and session logs
Settingssystem.settings, system.server_settingsConfiguration values
Time-Series Chartssystem.metric_log, system.query_logHistorical 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:

TableWhen CreatedFeature Impact
system.text_logMust be enabled in configServer logs viewer
system.session_logMust be enabled in configSession logs viewer
system.crash_logCreated when crashes occurCrash logs viewer
system.metric_logMust be enabled in configTime-series monitoring charts
system.query_logEnabled by defaultQuery 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

  1. Navigate to http://localhost:3000 (opens in a new tab)
  2. Enter your ClickHouse credentials:
    • Username: Your ClickHouse user
    • Password: Your ClickHouse password
  3. 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:

FeatureDescriptionRequired Permission
SQL ConsoleExecute queries with syntax highlighting and auto-completioncanExecuteQueries
Table ExplorerBrowse databases, tables, and partscanBrowseTables
Query MonitoringMonitor running queries and view historycanViewProcesses
Cluster HealthCPU, memory, merges, and Keeper statuscanViewCluster
Access ControlManage users and rolescanManageUsers
LoggingView system and query logscanViewCluster

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:

  1. ClickLens authenticates against your ClickHouse server
  2. Your grants are queried from system.grants (via Lens Client)
  3. Grants are mapped to UI permission flags
  4. The UI shows only what you have permission to access

8.2. Permission Flags

Permission FlagDerived FromFeature Enabled
canManageUsersACCESS MANAGEMENT grantUser/Role Management
canViewProcessesSELECT ON system.processesQuery Monitoring
canKillQueriesKILL QUERY grantQuery Termination
canViewClusterSELECT ON system.clustersCluster Monitoring
canBrowseTablesSHOW TABLES grantTable Explorer
canExecuteQueriesSELECT on any databaseSQL Console
canDiscoverSHOW TABLES + SELECTDiscover Feature
canViewSettingsSELECT ON system.settingsSettings Module
canViewServerLogsSELECT ON system.text_logServer Logs Tab
canViewSessionLogsSELECT ON system.session_logSession Logs Tab
canViewCrashLogsSELECT ON system.crash_logCrash Logs Tab

8.3. Feature Roles

ClickLens defines 6 predefined ClickHouse roles that bundle common permission sets:

RolePurposeRequired Grants
clicklens_table_explorerBrowse schemasSHOW DATABASES, SHOW TABLES, SELECT ON system.{tables,columns,parts,replicas,mutations,merges}
clicklens_query_monitorMonitor queriesKILL QUERY, SELECT ON system.{processes,query_log,query_cache}
clicklens_cluster_monitorMonitor clusterSELECT ON system.{clusters,replicas,metrics,events,disks,replication_queue,asynchronous_metrics}
clicklens_user_adminManage users/rolesACCESS MANAGEMENT ON *.*
clicklens_table_adminDDL operationsTRUNCATE, OPTIMIZE ON *.*
clicklens_settings_adminView configurationSELECT 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:

  1. Verify CLICKHOUSE_HOST and CLICKHOUSE_PORT are correct
  2. Ensure the HTTP interface is enabled (not just native protocol)
  3. Check firewall rules
  4. Verify ClickHouse is running: curl http://localhost:8123/ping

9.2. Permission Issues

Problem: Features not showing on dashboard

Solutions:

  1. Check your ClickHouse grants: SHOW GRANTS FOR current_user()
  2. Ensure required system tables are accessible
  3. Verify the Lens service user has proper permissions
  4. Check if you're using XML-configured users (see note above)

9.3. Session Issues

Problem: Frequent session expirations

Solutions:

  1. Ensure SESSION_SECRET is consistent across restarts
  2. Check cookie settings if behind a proxy (DISABLE_SECURE_COOKIES)
  3. Verify the secret is at least 32 characters

9.4. SSL Certificate Errors

Problem: SSL certificate verification failed

Solutions:

  1. Set CLICKHOUSE_VERIFY=false for self-signed certificates
  2. Or install the CA certificate in the container
  3. Ensure CLICKHOUSE_SECURE=true if using HTTPS

9.5. Redis Connection Issues

Problem: Redis caching not working

Solutions:

  1. Verify Redis is running: redis-cli ping should return PONG
  2. Check REDIS_URL environment variable is correct
  3. Ensure Redis is accessible from ClickLens container (network connectivity)
  4. Verify Redis port (default 6379) is not blocked by firewall
  5. 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