Prometheus protocols
暴露指标
注意
如果您正在使用 ClickHouse Cloud,您可以使用 Prometheus 集成将指标暴露给 Prometheus。
ClickHouse 可以暴露自己的指标,以便 Prometheus 进行抓取
<prometheus>
<port>9363</port>
<endpoint>/metrics</endpoint>
<metrics>true</metrics>
<asynchronous_metrics>true</asynchronous_metrics>
<events>true</events>
<errors>true</errors>
</prometheus>
Section `<prometheus.handlers>` can be used to make more extended handlers.
This section is similar to [<http_handlers>](/en/interfaces/http) but works for prometheus protocols:
```xml
<prometheus>
<port>9363</port>
<handlers>
<my_rule_1>
<url>/metrics</url>
<handler>
<type>expose_metrics</type>
<metrics>true</metrics>
<asynchronous_metrics>true</asynchronous_metrics>
<events>true</events>
<errors>true</errors>
</handler>
</my_rule_1>
</handlers>
</prometheus>
设置
名称 | 默认值 | 描述 |
---|---|---|
port | none | 用于服务暴露指标协议的端口。 |
endpoint | /metrics | 用于 Prometheus 服务器抓取指标的 HTTP 端点。以 / 开头。不应与 <handlers> 部分一起使用。 |
url / headers / method | none | 用于查找请求的匹配处理程序的过滤器。类似于 <http_handlers> 部分中同名的字段。 |
metrics | true | 暴露来自 system.metrics 表的指标。 |
asynchronous_metrics | true | 暴露来自 system.asynchronous_metrics 表的当前指标值。 |
events | true | 暴露来自 system.events 表的指标。 |
errors | true | 暴露自上次服务器重启以来发生的按错误代码分类的错误数量。此信息也可以从 system.errors 中获取。 |
检查(将 127.0.0.1 替换为您的 ClickHouse 服务器的 IP 地址或主机名)
curl 127.0.0.1:9363/metrics
Remote-write 协议
ClickHouse 支持 remote-write 协议。数据通过此协议接收并写入 TimeSeries 表(应预先创建)。
<prometheus>
<port>9363</port>
<handlers>
<my_rule_1>
<url>/write</url>
<handler>
<type>remote_write</type>
<database>db_name</database>
<table>time_series_table</table>
</handler>
</my_rule_1>
</handlers>
</prometheus>
设置
名称 | 默认值 | 描述 |
---|---|---|
port | none | 用于服务 remote-write 协议的端口。 |
url / headers / method | none | 用于查找请求的匹配处理程序的过滤器。类似于 <http_handlers> 部分中同名的字段。 |
table | none | 用于写入通过 remote-write 协议接收的数据的 TimeSeries 表的名称。此名称可以选择性地包含数据库的名称。 |
database | none | 数据库的名称,如果未在 table 设置中指定,则 table 设置中指定的表位于该数据库中。 |
Remote-read 协议
ClickHouse 支持 remote-read 协议。数据从 TimeSeries 表中读取并通过此协议发送。
<prometheus>
<port>9363</port>
<handlers>
<my_rule_1>
<url>/read</url>
<handler>
<type>remote_read</type>
<database>db_name</database>
<table>time_series_table</table>
</handler>
</my_rule_1>
</handlers>
</prometheus>
设置
名称 | 默认值 | 描述 |
---|---|---|
port | none | 用于服务 remote-read 协议的端口。 |
url / headers / method | none | 用于查找请求的匹配处理程序的过滤器。类似于 <http_handlers> 部分中同名的字段。 |
table | none | 用于读取要通过 remote-read 协议发送的数据的 TimeSeries 表的名称。此名称可以选择性地包含数据库的名称。 |
database | none | 数据库的名称,如果未在 table 设置中指定,则 table 设置中指定的表位于该数据库中。 |
多协议配置
多个协议可以在一个地方一起指定
<prometheus>
<port>9363</port>
<handlers>
<my_rule_1>
<url>/metrics</url>
<handler>
<type>expose_metrics</type>
<metrics>true</metrics>
<asynchronous_metrics>true</asynchronous_metrics>
<events>true</events>
<errors>true</errors>
</handler>
</my_rule_1>
<my_rule_2>
<url>/write</url>
<handler>
<type>remote_write</type>
<table>db_name.time_series_table</table>
</handler>
</my_rule_2>
<my_rule_3>
<url>/read</url>
<handler>
<type>remote_read</type>
<table>db_name.time_series_table</table>
</handler>
</my_rule_3>
</handlers>
</prometheus>