ClickHouse Exporter

ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS)。 官方文档: https://clickhouse.tech/docs/en/ ,建议查看英文文档,中文文档由于机器翻译的问题,逻辑混乱,没法使用。

ClickHouse 可以自身提供 Metric 数据供 Prometheus 来进行获取

  • endpoint – HTTP endpoint for scraping metrics by prometheus server. Start from ‘/’.
  • port – Port for endpoint.
  • metrics – Flag that sets to expose metrics from the system.metrics table.
  • events – Flag that sets to expose metrics from the system.events table.
  • asynchronous_metrics – Flag that sets to expose current metrics values from the system.asynchronous_metrics table.

修改配置文件/etc/clickhouse-server/config.xml ,使用如下参数打开 ClickHouse 的监控。记得要重新加载配置文件使的配置文件生效。

示例如下:

<prometheus>
        <endpoint>/metrics</endpoint>
        <port>8001</port>
        <metrics>true</metrics>
        <events>true</events>
        <asynchronous_metrics>true</asynchronous_metrics>
    </prometheus>

设置好以后可以访问来确认数据已经正常提取。

curl localhost:8001/metrics

关于监控数据的展示和监控项的选择可以参考 10.8 节,ClickHouse 监控 文章。

Exporter

官方维护了一个 Exporter ,有时间可以测试一下。

https://github.com/ClickHouse/clickhouse_exporter 这个看上去是官方在维护的 。

这个组件官方并没有提供已经构建好的二进制文件,如果要使用的话,需要下载代码,搭建 Golang 语言环境,自己进行编译。

或者也可以直接构建成 Docker image ,Dockerfile 里边包含了 Golang 的构建环境,并且使用 Docker 的多阶段构建,最终的是一个基于 frolvlad/alpine-glibc:alpine-3.13 的运行环境。

构建命令:

docker build . -t clickhouse-exporter

构建好以后可以使用如下命令运行,

docker run -d -p 9116:9116 clickhouse-exporter -scrape_uri=http://clickhouse-url:8123/

如果 ClickHouse 有认证相关,可以使用 CLICKHOUSE_USERCLICKHOUSE_PASSWORD 通过环境变量的方式传递给 clickhouse-exporter 。

综合看下来,感觉这个组件有些仓促,使用 ClickHouse 配置文件提供的监控指标也不错,

Grafana 作为监控采集

对于 Grafana ,可以选择 数据源为 ClickHouse ,从 Clickhouse 数据库中直接查询监控数据,用来监控。查询其他数据用来展示其他功能。

监控数据 Metrics 指标位于 ClickHouse 的 system.metrics, system.events, and system.asynchronous_metrics 这三张表

system.metrics

SELECT * FROM system.metrics LIMIT 10
┌─metric─────────────────────┬─value─┬─description──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Query                      │     1 │ Number of executing queries                                                                                                                                                                      │
│ Merge                      │     0 │ Number of executing background merges                                                                                                                                                            │
│ PartMutation               │     0 │ Number of mutations (ALTER DELETE/UPDATE)                                                                                                                                                        │
│ ReplicatedFetch            │     0 │ Number of data parts being fetched from replicas                                                                                                                                                │
│ ReplicatedSend             │     0 │ Number of data parts being sent to replicas                                                                                                                                                      │
│ ReplicatedChecks           │     0 │ Number of data parts checking for consistency                                                                                                                                                    │
│ BackgroundPoolTask         │     0 │ Number of active tasks in BackgroundProcessingPool (merges, mutations, fetches, or replication queue bookkeeping)                                                                                │
│ BackgroundSchedulePoolTask │     0 │ Number of active tasks in BackgroundSchedulePool. This pool is used for periodic ReplicatedMergeTree tasks, like cleaning old data parts, altering data parts, replica re-initialization, etc.   │
│ DiskSpaceReservedForMerge  │     0 │ Disk space reserved for currently running background merges. It is slightly more than the total size of currently merging parts.                                                                     │
│ DistributedSend            │     0 │ Number of connections to remote servers sending data that was INSERTed into Distributed tables. Both synchronous and asynchronous mode.                                                          │
└────────────────────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

system.events

SELECT * FROM system.events LIMIT 5
┌─event─────────────────────────────────┬─value─┬─description────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Query                                 │    12 │ Number of queries to be interpreted and potentially executed. Does not include queries that failed to parse or were rejected due to AST size limits, quota limits or limits on the number of simultaneously running queries. May include internal queries initiated by ClickHouse itself. Does not count subqueries.                  │
│ SelectQuery                           │     8 │ Same as Query, but only for SELECT queries.                                                                                                                                                                                                                │
│ FileOpen                              │    73 │ Number of files opened.                                                                                                                                                                                                                                    │
│ ReadBufferFromFileDescriptorRead      │   155 │ Number of reads (read/pread) from a file descriptor. Does not include sockets.                                                                                                                                                                             │
│ ReadBufferFromFileDescriptorReadBytes │  9931 │ Number of bytes read from file descriptors. If the file is compressed, this will show the compressed data size.                                                                                                                                              │
└───────────────────────────────────────┴───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

system.asynchronous_metrics

SELECT * FROM system.asynchronous_metrics LIMIT 10
┌─metric──────────────────────────────────┬──────value─┐
│ jemalloc.background_thread.run_interval │          0 │
│ jemalloc.background_thread.num_runs     │          0 │
│ jemalloc.background_thread.num_threads  │          0 │
│ jemalloc.retained                       │  422551552 │
│ jemalloc.mapped                         │ 1682989056 │
│ jemalloc.resident                       │ 1656446976 │
│ jemalloc.metadata_thp                   │          0 │
│ jemalloc.metadata                       │   10226856 │
│ UncompressedCacheCells                  │          0 │
│ MarkCacheFiles                          │          0 │
└─────────────────────────────────────────┴────────────┘

参考链接:

results matching ""

    No results matching ""