侧边栏壁纸
博主头像
船长博主等级

专注于云原生运维,致敬每个爱学习的你

  • 累计撰写 35 篇文章
  • 累计创建 10 个标签
  • 累计收到 10 条评论

ClickHouse 集群监控

船长
2022-01-29 / 1 评论 / 1 点赞 / 573 阅读 / 3,103 字
温馨提示:
本文最后更新于 2022-04-18,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

概述

Clickhouse 运行时会将一些个自身的运行状态记录到众多系统表中( system.*)。所以我 们对于 CH 自身的一些运行指标的监控数据,也主要来自这些系统表。

但是直接查询这些系统表会有一些不足之处

  • 这种方式太过底层,不够直观,我们还需要在此之上实现可视化展示
  • 系统表只记录了CH自己的运行指标,有些时候我们需要外部系统的指标进行关联分析,列如ZooKeeper、服务器 CPU、IO 等等。

现在 Prometheus + Grafana 的组合比较流行,安装简单易上手,可以集成很多框架,包

括服务器的负载, 其中 Prometheus 负责收集各类系统的运行指标; Grafana 负责可视化的

部分。

ClickHouse 从 v20.1.2.4 开始,内置了对接 Prometheus 的功能,配置的方式也很简单,

可以将其作为 Prometheus 的 Endpoint 服务,从而自动的将 metrics 、 events 和

asynchronous_metrics 三张系统的表的数据发送给 Prometheus。

ClickHouse 配置

编辑/etc/clickhouse-server/config.xml,打开如下配置:

 <prometheus>
 <endpoint>/metrics</endpoint>
 <port>9363</port>
 <metrics>true</metrics>
 <events>true</events>
 <asynchronous_metrics>true</asynchronous_metrics>
 <status_info>true</status_info>
 </prometheus>

重启Clickhouse

systemctl restart clickhouse-server

Prometheus 安装

### 基础环境准备
 
# 查看系统版本
$ cat  /etc/redhat-release
CentOS Linux
release 7.7.1908 (Core)
 
 
# 查看系统内核
$ uname -r
3.10.0-1062.18.1.el7.x86_64
 
 
# 安装目录
$ pwd
/application/prometheus
# 数据存储目录
$ pwd
/application/data/prometheus_data

### 安装Prometheus
 
 

# 下载prometheus安装包
$ wget https://github.com/prometheus/prometheus/releases/download/v2.20.0/prometheus-2.20.0.linux-amd64.tar.gz
# 解压安装包
$ tar xzvf prometheus-v2.20.0.linux-amd64.tar.gz
$ mv prometheus-v2.20.0.linux-amd64 ../prometheus
# 创建启动用户
$ groupadd prometheus
$ useradd -g prometheus -s /sbin/nologin prometheus
 
# 创建prometheus存储目录并授权
$ mkdir -p /application/data/prometheus_data
$ chown -R prometheus.prometheus prometheus_data/

**prometheus.yml配置文件说明**
 
global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s
  # 我们可以附加一些指定标签到采样点度量标签列表中, 用于和第三方系统进行通信, 包括:federation, remote storage, Alertmanager
  external_labels:
    # 下面就是拉取自身服务采样点数据配置
    monitor: 'codelab-monitor'
scrape_configs:
  # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上
  - job_name: 'prometheus'
    # 覆盖global的采样点,拉取时间间隔5s
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
      
  - job_name: 'ck'
    static_configs:
    - targets: ['192.168.1.104:9363']
 
 
 
### 创建Prometheus系统服务并启动
 
 

$ vim /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/application/prometheus/prometheus --config.file=/application/prometheus/prometheus.yml --storage.tsdb.path=/application/data/prometheus_data --web.enable-lifecycle
Restart=on-failure
[Install]
WantedBy=multi-user.target
 
 
# 注释
# 指定配置文件
--config.file="prometheus.yml"
# 指定监听地址端口
--web.listen-address="0.0.0.0:9090"
# 最大连接数
--web.max-connections=512
# tsdb数据存储的目录,默认当前data/
--storage.tsdb.path="data/"
# premetheus 存储数据的时间,默认保存15天
--storage.tsdb.retention=15d
 
$ systemctl start prometheus
$ systemctl status prometheus
$ systemctl enable prometheus

Grafana 安装

$ wget -P /usr/local/src https://dl.grafana.com/oss/release/grafana-7.1.2-1.x86_64.rpm  # 下载安装包
$ cd /usr/local/src
$ yum install -y grafana-7.1.2-1.x86_64.rpm
$ /etc/init.d/grafana-server start   # 启动grafana服务

### 登录访问
访问:http://192.168.1.110:3000,默认账号/密码:admin/admin

Grafana 集成 Prometheus

添加数据源

点击配置,点击 Data Sources:

点击添加按钮:

找到 Prometheus,点击 Select

配置 Prometheus Server 地址:

点击下方的 Save&Test,出现绿色的提示框,表示与 Prometheus 正常联通

点击 Back 返回即可,可以看到 Data Sources 页面,出现了添加的 Prometheus:

添加监控面板

点击左侧 ”+”号,选择 import:

https://img.kubesre.com/img/clickhouse-metrics-on-settings_rev1.json

展示监控:

1

评论区