Skip to main content

Clickhouse

Clickhouse is an open-source column-oriented DBMS (columnar database management system) for online analytical processing (OLAP) that allows users to generate analytical reports using SQL queries in real-time.

Setting up Clickhouse

The fastest way to set up Clickhouse for testing is to use a docker container:

docker run \
-p 9000:9000 \
--name some-clickhouse-server \
--ulimit nofile=262144:262144 \
-e CLICKHOUSE_USER=user \
-e CLICKHOUSE_PASSWORD=pass \
clickhouse/clickhouse-server

Setting up the FlowG pipeline

First, let's create a "Clickhouse Forwarder" named clickhouse, with the following configuration:

PropertyValueComment
Clickhouse connection addresslocalhost:9000The Clickhouse client endpoint
Database namedefaultThe default database created in the container
Table namedefaultThe table name to use for the logs
Database usernameuserThe name of the user specified in the command
Database passwordpassThe password of the user specified in the command
Use TLSuncheckedThe container doesn't set up TLS, so, for testing, we disable it
Clickhouse Forwarder Configuration

Then, create a pipeline that forwards logs to the clickhouse forwarder:

Pipeline with Clickhouse Forwarder

And that's it!

Testing

You can test the setup by sending a log to the pipeline using the logger command:

logger -n localhost -P 5514 -t my-app 'hello world'

The log will be forwarded to your Clickhouse instance and stored in the specified table.

To query the clickhouse instance for the logs, run the following command:

docker exec some-clickhouse-server clickhouse-client 'select * from default order by timestamp;'

Data model in Clickhouse

Table schema:

CREATE TABLE IF NOT EXISTS tablename (
id UUID NOT NULL PRIMARY KEY,
timestamp DateTime64(3, 'UTC') NOT NULL,
fields Map(String, String) NOT NULL,
) ENGINE = MergeTree