ClickHouse/docs/zh/engines/table-engines/mergetree-family/graphitemergetree.md

175 lines
5.5 KiB
Markdown
Raw Normal View History

2020-04-03 13:23:32 +00:00
---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_priority: 38
toc_title: GraphiteMergeTree
2020-04-03 13:23:32 +00:00
---
# GraphiteMergeTree {#graphitemergetree}
此引擎专为细化和聚合/平均rollup) [石墨](http://graphite.readthedocs.io/en/latest/index.html) 戴达 对于想要使用ClickHouse作为Graphite的数据存储的开发人员来说这可能会有所帮助。
2020-04-03 13:23:32 +00:00
您可以使用任何ClickHouse表引擎来存储石墨数据如果你不需要汇总但如果你需要一个汇总使用 `GraphiteMergeTree`. 该引擎减少了存储量并提高了Graphite查询的效率。
2020-04-03 13:23:32 +00:00
引擎继承从属性 [MergeTree](mergetree.md).
2020-04-03 13:23:32 +00:00
## 创建表 {#creating-table}
2020-04-03 13:23:32 +00:00
``` sql
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, ...]
```
请参阅的详细说明 [CREATE TABLE](../../../sql-reference/statements/create.md#create-table-query) 查询。
2020-04-03 13:23:32 +00:00
Graphite数据的表应具有以下数据的列:
2020-04-03 13:23:32 +00:00
- 公制名称(石墨传感器)。 数据类型: `String`.
2020-04-03 13:23:32 +00:00
- 测量度量的时间。 数据类型: `DateTime`.
2020-04-03 13:23:32 +00:00
- 度量值。 数据类型:任何数字。
2020-04-03 13:23:32 +00:00
- 指标的版本。 数据类型:任何数字。
2020-04-03 13:23:32 +00:00
如果版本相同ClickHouse会保存版本最高或最后写入的行。 其他行在数据部分合并期间被删除。
2020-04-03 13:23:32 +00:00
应在汇总配置中设置这些列的名称。
2020-04-03 13:23:32 +00:00
**GraphiteMergeTree参数**
2020-04-03 13:23:32 +00:00
- `config_section` — Name of the section in the configuration file, where are the rules of rollup set.
**查询子句**
2020-04-03 13:23:32 +00:00
当创建一个 `GraphiteMergeTree` 表,相同 [条款](mergetree.md#table_engine-mergetree-creating-a-table) 是必需的,因为当创建 `MergeTree` 桌子
2020-04-03 13:23:32 +00:00
<details markdown="1">
<summary>不推荐使用的创建表的方法</summary>
2020-04-03 13:23:32 +00:00
!!! attention "注意"
不要在新项目中使用此方法,如果可能的话,请将旧项目切换到上述方法。
2020-04-03 13:23:32 +00:00
``` sql
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)
```
所有参数除外 `config_section` 具有相同的含义 `MergeTree`.
2020-04-03 13:23:32 +00:00
- `config_section` — Name of the section in the configuration file, where are the rules of rollup set.
</details>
## 汇总配置 {#rollup-configuration}
2020-04-03 13:23:32 +00:00
DOCS-624: Fixing links to nowhere (#10675) * enbaskakova-DOCSUP-652 (#101) * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/sql_reference/aggregate_functions/combinators.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" * "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited" Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: BayoNet <da-daos@yandex.ru> * Revert "enbaskakova-DOCSUP-652 (#101)" (#107) This reverts commit 639fee7610f28e421d14e535b7def3f466e7efca. * CLICKHOUSEDOCS-624: Fixed links. Was 60, became 13. * CLICKHOUSEDOCS-624: Finished fix links in Enlish version. * CLICKHOUSEDOCS-624: Fixed RU links Co-authored-by: elenaspb2019 <47083263+elenaspb2019@users.noreply.github.com> Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru> Co-authored-by: Sergei Shtykov <bayonet@yandex-team.ru>
2020-05-06 06:13:29 +00:00
汇总的设置由 [graphite\_rollup](../../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-graphite) 服务器配置中的参数。 参数的名称可以是any。 您可以创建多个配置并将它们用于不同的表。
2020-04-03 13:23:32 +00:00
汇总配置结构:
2020-04-03 13:23:32 +00:00
required-columns
patterns
### 必填列 {#required-columns}
2020-04-03 13:23:32 +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`. 默认值: `Value`.
2020-04-03 13:23:32 +00:00
- `version_column_name` — The name of the column storing the version of the metric. Default value: `Timestamp`.
### 模式 {#patterns}
2020-04-03 13:23:32 +00:00
的结构 `patterns` 科:
2020-04-03 13:23:32 +00:00
``` text
pattern
regexp
function
pattern
regexp
age + precision
...
pattern
regexp
function
age + precision
...
pattern
...
default
function
age + precision
...
```
!!! warning "注意"
模式必须严格排序:
2020-04-03 13:23:32 +00:00
1. Patterns without `function` or `retention`.
1. Patterns with both `function` and `retention`.
1. Pattern `default`.
在处理行时ClickHouse会检查以下内容中的规则 `pattern` 部分。 每个 `pattern` (包括 `default`)部分可以包含 `function` 聚合参数, `retention` 参数或两者兼而有之。 如果指标名称匹配 `regexp`,从规则 `pattern` 部分sections节的应用;否则,从规则 `default` 部分被使用。
2020-04-03 13:23:32 +00:00
字段为 `pattern``default` 科:
2020-04-03 13:23:32 +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]`.
### 配置示例 {#configuration-example}
2020-04-03 13:23:32 +00:00
``` xml
<graphite_rollup>
<version_column_name>Version</version_column_name>
<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>
```
[原始文章](https://clickhouse.tech/docs/en/operations/table_engines/graphitemergetree/) <!--hide-->