You need to enable JavaScript to run this app.
导航

Metabase

最近更新时间2024.04.29 15:04:29

首次发布时间2024.04.29 15:04:29

环境准备

运行 Metabase Docker

docker run -d -p 3000:3000 --name metabase metabase/metabase

具体用法可参考Metabase官方网站:https://www.metabase.com/start/oss/
在浏览器中打开 http://localhost:3000/ 以访问Metabase界面。

下载 clickhouse 插件 jar 文件

Because of the docker container deployment of metabase, you need to enter the container to download the clickhouse metabase plugin jar to the plugins directory.
因为Metabase通过 docker 容器部署,所以需要进入容器下载 clickhouse metabase 插件 jar 到plugins目录下。

docker exec -it <container_id> bash
cd plugins
wget https://github.com/ClickHouse/metabase-clickhouse-driver/releases/download/1.3.3/clickhouse.metabase-driver.jar

退出并重启容器

docker restart <container_id>

重新打开 http://localhost:3000/ 以访问Metabase界面。

ByteHouse 配置

数据准备

这里以SSB数据集为例,执行下面的命令生成数据。请注意,如果您不需要执行性能测试,您可以缩减数据量。

./dbgen -s 1 -T c 
./dbgen -s 1 -T l 
./dbgen -s 1 -T p 
./dbgen -s 1 -T s

Metadata视图准备

目前您需要手动(自动化逻辑正在进行中)在ByteHouse后端创建系统视图。这用于为Metadata提供元数据查找。请注意替换您的<account_id>
Metabase需要将以下视图用于同步数据库元数据和表元数据。

CREATE DATABASE `<account_id>.system`;

-- the USE step is very important, 
-- if you don't execute this, you'll
-- end up creating the tables in the default database
USE `<account_id>.system`; 


-- this is an additional table required from quickbi
CREATE VIEW settings AS
SELECT
  `name`,
  `value`,
  `changed`,
  `description`,
  `min`,
  `max`,
  `readonly`,
  `type`
FROM
  system.settings
  
CREATE VIEW databases as SELECT
substring_index(name, '.', -1) `name`,
    `engine`,
    `data_path` ,
    `metadata_path` ,
    `uuid` 
FROM system.databases
WHERE system.databases.name LIKE '<account_id>%'

CREATE VIEW tables as
SELECT
    substring_index(database, '.', -1) `database`, 
    name,
    uuid,
    engine,
    is_temporary,
    data_paths,
    metadata_path,
    metadata_modification_time,
    dependencies_database,
    dependencies_table,
    create_table_query,
    engine_full,
    partition_key,
    sorting_key,
    primary_key,
    sampling_key,
    storage_policy,
    total_rows,
    total_bytes,
    lifetime_rows,
    lifetime_bytes,
    comment
FROM system.tables
WHERE system.tables.database LIKE '<account_id>%'

CREATE VIEW columns as
SELECT
    substring_index(database, '.', -1) `database`, 
    table,
    name,
    type,
    position,
    default_kind,
    default_expression,
    data_compressed_bytes,
    data_uncompressed_bytes,
    marks_bytes,
    comment,
    is_in_partition_key,
    is_in_sorting_key,
    is_in_primary_key,
    is_in_sampling_key,
    compression_codec
FROM system.columns
WHERE system.columns.database LIKE '<account_id>%'

CREATE VIEW mutations as SELECT  
substring_index(database, '.', -1) `database`, 
    `table` ,
    `mutation_id` ,
    `query_id` ,
    `command` ,
    `create_time` ,
    `block_numbers.partition_id` ,
    `block_numbers.number`,
    `parts_to_do_names` ,
    `parts_to_do` ,
    `is_done` ,
    `latest_failed_part` ,
    `latest_fail_time` ,
    `latest_fail_reason` 
FROM cnch(server, system.mutations)
WHERE database LIKE '<account_id>%'

连接 Metabase

添加数据库

首页->设置->管理员设置->数据库->添加数据库->配置数据库->保存数据库

  1. 单击右上角的齿轮图标,然后选择管理设置 Admin Settings 以访问您的Metabase管理页面
  2. 单击 添加数据库 Add a database。或者,您可以单击**“数据库 Databases”选项卡并选择“添加数据库 Add database”**按钮。
  3. 如果您的驱动程序安装成功,您将在数据库类型 Database type 的下拉菜单中看到ClickHouse

图片

  1. 为您的数据库指定一个显示名称 Display name,请使用您喜欢的任何名称。
  2. 输入 ByteHouse 数据库的连接详细信息。
  • Host:网关地址
  • Port:8123
  • Username: 用户名
  • Password: ByteHouseAccess Token
  • Databases: 数据库名
  • Use a secure connection (SSL): 启用安全连接(SSL)

图片

  1. 单击**“保存”**按钮,Metabase 将扫描数据库中的表。