2020-04-03 13:23:32 +00:00
---
toc_priority: 38
toc_title: GraphiteMergeTree
---
2020-04-08 14:22:25 +00:00
# GraphiteMergeTree {#graphitemergetree}
2017-12-28 15:13:23 +00:00
2019-01-18 16:07:48 +00:00
This engine is designed for thinning and aggregating/averaging (rollup) [Graphite ](http://graphite.readthedocs.io/en/latest/index.html ) data. It may be helpful to developers who want to use ClickHouse as a data store for Graphite.
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
You can use any ClickHouse table engine to store the Graphite data if you don’ t need rollup, but if you need a rollup use `GraphiteMergeTree` . The engine reduces the volume of storage and increases the efficiency of queries from Graphite.
2017-12-28 15:13:23 +00:00
2020-06-18 08:24:31 +00:00
The engine inherits properties from [MergeTree ](../../../engines/table-engines/mergetree-family/mergetree.md ).
2017-12-28 15:13:23 +00:00
2020-03-18 18:43:51 +00:00
## Creating a Table {#creating-table}
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2018-10-19 11:25:22 +00:00
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
Path String,
Time DateTime,
Value < Numeric_type > ,
Version < Numeric_type >
...
) ENGINE = GraphiteMergeTree(config_section)
[PARTITION BY expr]
[ORDER BY expr]
[SAMPLE BY expr]
[SETTINGS name=value, ...]
```
2020-07-09 15:10:35 +00:00
See a detailed description of the [CREATE TABLE ](../../../sql-reference/statements/create/table.md#create-table-query ) query.
2018-10-19 11:25:22 +00:00
2019-05-29 05:42:22 +00:00
A table for the Graphite data should have the following columns for the following data:
2018-10-19 11:25:22 +00:00
2020-03-21 04:11:51 +00:00
- Metric name (Graphite sensor). Data type: `String` .
2020-03-20 10:10:48 +00:00
2020-03-21 04:11:51 +00:00
- Time of measuring the metric. Data type: `DateTime` .
2020-03-20 10:10:48 +00:00
2020-03-21 04:11:51 +00:00
- Value of the metric. Data type: any numeric.
2020-03-20 10:10:48 +00:00
2020-03-21 04:11:51 +00:00
- Version of the metric. Data type: any numeric.
2018-10-19 11:25:22 +00:00
2020-03-21 04:11:51 +00:00
ClickHouse saves the rows with the highest version or the last written if versions are the same. Other rows are deleted during the merge of data parts.
2018-10-19 11:25:22 +00:00
The names of these columns should be set in the rollup configuration.
**GraphiteMergeTree parameters**
2020-03-21 04:11:51 +00:00
- `config_section` — Name of the section in the configuration file, where are the rules of rollup set.
2018-10-19 11:25:22 +00:00
**Query clauses**
2020-06-18 08:24:31 +00:00
When creating a `GraphiteMergeTree` table, the same [clauses ](../../../engines/table-engines/mergetree-family/mergetree.md#table_engine-mergetree-creating-a-table ) are required, as when creating a `MergeTree` table.
2018-10-19 11:25:22 +00:00
2020-03-20 10:10:48 +00:00
< details markdown = "1" >
< summary > Deprecated Method for Creating a Table< / summary >
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
!!! attention "Attention"
2018-10-19 11:25:22 +00:00
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2018-10-19 11:25:22 +00:00
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
EventDate Date,
Path String,
Time DateTime,
Value < Numeric_type > ,
Version < Numeric_type >
...
) ENGINE [=] GraphiteMergeTree(date-column [, sampling_expression], (primary, key), index_granularity, config_section)
```
All of the parameters excepting `config_section` have the same meaning as in `MergeTree` .
2017-12-28 15:13:23 +00:00
2020-03-21 04:11:51 +00:00
- `config_section` — Name of the section in the configuration file, where are the rules of rollup set.
2020-03-20 10:10:48 +00:00
2018-10-19 11:25:22 +00:00
< / details >
2017-12-28 15:13:23 +00:00
2020-04-03 13:23:32 +00:00
## Rollup Configuration {#rollup-configuration}
2017-12-28 15:13:23 +00:00
2020-10-13 17:23:29 +00:00
The settings for rollup are defined by the [graphite_rollup ](../../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-graphite ) parameter in the server configuration. The name of the parameter could be any. You can create several configurations and use them for different tables.
2017-12-28 15:13:23 +00:00
2018-10-19 11:25:22 +00:00
Rollup configuration structure:
2017-12-28 15:13:23 +00:00
2020-03-21 04:11:51 +00:00
required-columns
patterns
2019-05-29 05:42:22 +00:00
2020-03-18 18:43:51 +00:00
### Required Columns {#required-columns}
2019-05-29 05:42:22 +00:00
2020-03-21 04:11:51 +00:00
- `path_column_name` — The name of the column storing the metric name (Graphite sensor). Default value: `Path` .
- `time_column_name` — The name of the column storing the time of measuring the metric. Default value: `Time` .
- `value_column_name` — The name of the column storing the value of the metric at the time set in `time_column_name` . Default value: `Value` .
- `version_column_name` — The name of the column storing the version of the metric. Default value: `Timestamp` .
2019-05-29 05:42:22 +00:00
2020-03-18 18:43:51 +00:00
### Patterns {#patterns}
2019-05-29 05:42:22 +00:00
Structure of the `patterns` section:
2020-03-20 10:10:48 +00:00
``` text
2019-02-20 16:16:46 +00:00
pattern
regexp
function
pattern
regexp
age + precision
...
2017-12-28 15:13:23 +00:00
pattern
regexp
function
2018-10-19 11:25:22 +00:00
age + precision
2017-12-28 15:13:23 +00:00
...
pattern
...
default
function
2018-10-19 11:25:22 +00:00
age + precision
2017-12-28 15:13:23 +00:00
...
```
2019-06-05 06:30:38 +00:00
!!! warning "Attention"
Patterns must be strictly ordered:
2019-02-28 09:44:30 +00:00
2020-03-21 04:11:51 +00:00
1. Patterns without `function` or `retention` .
1. Patterns with both `function` and `retention` .
1. Pattern `default` .
2019-02-28 09:44:30 +00:00
2019-05-29 05:42:22 +00:00
When processing a row, ClickHouse checks the rules in the `pattern` sections. Each of `pattern` (including `default` ) sections can contain `function` parameter for aggregation, `retention` parameters or both. If the metric name matches the `regexp` , the rules from the `pattern` section (or sections) are applied; otherwise, the rules from the `default` section are used.
2017-12-28 15:13:23 +00:00
2018-10-19 11:25:22 +00:00
Fields for `pattern` and `default` sections:
2020-03-21 04:11:51 +00:00
- `regexp` – A pattern for the metric name.
- `age` – The minimum age of the data in seconds.
- `precision` – How precisely to define the age of the data in seconds. Should be a divisor for 86400 (seconds in a day).
- `function` – The name of the aggregating function to apply to data whose age falls within the range `[age, age + precision]` .
2018-10-19 11:25:22 +00:00
2020-03-18 18:43:51 +00:00
### Configuration Example {#configuration-example}
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` xml
2017-12-28 15:13:23 +00:00
< graphite_rollup >
2018-10-19 11:25:22 +00:00
< version_column_name > Version< / version_column_name >
2017-12-28 15:13:23 +00:00
< pattern >
< regexp > click_cost< / regexp >
< function > any< / function >
< retention >
< age > 0< / age >
< precision > 5< / precision >
< / retention >
< retention >
< age > 86400< / age >
< precision > 60< / precision >
< / retention >
< / pattern >
< default >
< function > max< / function >
< retention >
< age > 0< / age >
< precision > 60< / precision >
< / retention >
< retention >
< age > 3600< / age >
< precision > 300< / precision >
< / retention >
< retention >
< age > 86400< / age >
< precision > 3600< / precision >
< / retention >
< / default >
< / graphite_rollup >
```
2018-04-23 06:20:21 +00:00
2020-01-30 10:34:55 +00:00
[Original article ](https://clickhouse.tech/docs/en/operations/table_engines/graphitemergetree/ ) <!--hide-->