GraphiteMergeTree

This engine is designed for thinning and aggregating/averaging (rollup) Graphite data. It may be helpful to developers who want to use ClickHouse as a data store for Graphite.

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.

The engine inherits properties from MergeTree.

Creating a Table

  1. CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
  2. (
  3. Path String,
  4. Time DateTime,
  5. Value <Numeric_type>,
  6. Version <Numeric_type>
  7. ...
  8. ) ENGINE = GraphiteMergeTree(config_section)
  9. [PARTITION BY expr]
  10. [ORDER BY expr]
  11. [SAMPLE BY expr]
  12. [SETTINGS name=value, ...]

See a detailed description of the CREATE TABLE query.

A table for the Graphite data should have the following columns for the following data:

  • Metric name (Graphite sensor). Data type: String.

  • Time of measuring the metric. Data type: DateTime.

  • Value of the metric. Data type: any numeric.

  • Version of the metric. Data type: any numeric.

    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.

The names of these columns should be set in the rollup configuration.

GraphiteMergeTree parameters

  • config_section — Name of the section in the configuration file, where are the rules of rollup set.

Query clauses

When creating a GraphiteMergeTree table, the same clauses are required, as when creating a MergeTree table.

Deprecated Method for Creating a Table

Attention

Do not use this method in new projects and, if possible, switch the old projects to the method described above.

  1. CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
  2. (
  3. EventDate Date,
  4. Path String,
  5. Time DateTime,
  6. Value <Numeric_type>,
  7. Version <Numeric_type>
  8. ...
  9. ) 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.

  • config_section — Name of the section in the configuration file, where are the rules of rollup set.

Rollup Configuration

The settings for rollup are defined by the graphite_rollup parameter in the server configuration. The name of the parameter could be any. You can create several configurations and use them for different tables.

Rollup configuration structure:

  1. required-columns
  2. patterns

Required Columns

  • 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.

Patterns

Structure of the patterns section:

  1. pattern
  2. regexp
  3. function
  4. pattern
  5. regexp
  6. age + precision
  7. ...
  8. pattern
  9. regexp
  10. function
  11. age + precision
  12. ...
  13. pattern
  14. ...
  15. default
  16. function
  17. age + precision
  18. ...

Attention

Patterns must be strictly ordered:

  1. Patterns without function or retention.
  2. Patterns with both function and retention.
  3. Pattern default.

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.

Fields for pattern and default sections:

  • 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].

Configuration Example

  1. <graphite_rollup>
  2. <version_column_name>Version</version_column_name>
  3. <pattern>
  4. <regexp>click_cost</regexp>
  5. <function>any</function>
  6. <retention>
  7. <age>0</age>
  8. <precision>5</precision>
  9. </retention>
  10. <retention>
  11. <age>86400</age>
  12. <precision>60</precision>
  13. </retention>
  14. </pattern>
  15. <default>
  16. <function>max</function>
  17. <retention>
  18. <age>0</age>
  19. <precision>60</precision>
  20. </retention>
  21. <retention>
  22. <age>3600</age>
  23. <precision>300</precision>
  24. </retention>
  25. <retention>
  26. <age>86400</age>
  27. <precision>3600</precision>
  28. </retention>
  29. </default>
  30. </graphite_rollup>

Original article