Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History
91 lines (77 loc) · 2.55 KB

File metadata and controls

91 lines (77 loc) · 2.55 KB

Building cluster

Replication

  • Configure clickhouse, see doc for more details.
  • Create Replicated tables
CREATE DATABASE graphite;

CREATE TABLE graphite.metrics
(
    date Date DEFAULT toDate(0),
    name String,
    level UInt16,
    parent String,
    updated DateTime DEFAULT now(),
    status Enum8('SIMPLE' = 0, 'BAN' = 1, 'APPROVED' = 2, 'HIDDEN' = 3, 'AUTO_HIDDEN' = 4)
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/single/graphite.metrics', '{replica}', updated)
PARTITION BY toYYYYMM(date)
ORDER BY (parent, name)
SETTINGS index_granularity = 1024;

CREATE TABLE graphite.data_lr
(
    metric String,
    value Float64,
    timestamp UInt32,
    date Date,
    updated UInt32
)
ENGINE = ReplicatedGraphiteMergeTree('/clickhouse/tables/graphite.data', '{replica}', 'graphite_rollup')
PARTITION BY toMonday(date) -- or, if you have low amount of data, then toYYYYMM(date)
ORDER BY (metric, timestamp)
SETTINGS index_granularity = 8192;

Sharding and Replication

CREATE DATABASE graphite;

CREATE TABLE graphite.metrics
(
    date Date DEFAULT toDate(0),
    name String,
    level UInt16,
    parent String,
    updated DateTime DEFAULT now(),
    status Enum8('SIMPLE' = 0, 'BAN' = 1, 'APPROVED' = 2, 'HIDDEN' = 3, 'AUTO_HIDDEN' = 4)
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/single/graphite.metrics', '{replica}', updated)
PARTITION BY toYYYYMM(date)
ORDER BY (parent, name)
SETTINGS index_granularity = 1024;

CREATE TABLE graphite.data_lr
(
    metric String,
    value Float64,
    timestamp UInt32,
    date Date,
    updated UInt32
)
ENGINE = ReplicatedGraphiteMergeTree('/clickhouse/tables/{shard}/graphite.data_lr', '{replica}', 'graphite_rollup')
PARTITION BY toMonday(date) -- or, if you have low amount of data, then toYYYYMM(date)
ORDER BY (metric, timestamp)
SETTINGS index_granularity = 8192;


CREATE TABLE graphite.data
(
    metric String,
    value Float64,
    timestamp UInt32,
    date Date,
    updated UInt32
)
ENGINE Distributed(CLICKHOUSE_CLUSTER_NAME, 'graphite', 'data_lr', sipHash64(metric));

Don't forget to replace CLICKHOUSE_CLUSTER_NAME with name from you config.

Notice: We use sharding only for data, couse metrics is small and contains only metric names.