【Clickhouse】Clickhouse 整合 Prometheus 监控 运行时状态

x33g5p2x  于2022-02-09 转载在 ClickHouse  
字(2.9k)|赞(0)|评价(0)|浏览(620)

1.概述

转载:ClickHouse运行时状态监控

类似:【clickhouse】docker 下 搭建 clickhouse 监控

Clickhouse 在运行时会将一些运行装白保存到系统表中,在对 clickhouse 进行监控时也会从这些系统表中获取数据了解 clickhouse 的运行状态。

clickhouse 元数据表中系统监控相关的表

但是直接查询这些系统表不能够直观的看到当前系统的状态,另外 clickhouse 外部的一些服务器相关的指标也查看不到,例如 CPU、IO 等信息。

推荐使用Prometheus + Grafana 的组合进行 clickhouse 监控,这个组合可以继承很多框架,并且Prometheus可以收集很多服务器的负载信息,Grafana 则负责对收集到的数据进行可视化的展示。

ClickHouse 从 v20.1.2.4 开始,内置了对接 Prometheus 的功能,配置的方式也很简单, 可以将其作为 Prometheus 的 Endpoint 服务,从而自动的将 metrics 、events 和 asynchronous_metrics 三张系统的表的数据发送给 Prometheus。

2. 配置 Clickhouse

vim /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

安装 Prometheus

3.1 介绍

Prometheus 是基于 Golang 语言编写,编译后的软件包,不依赖于任何的第三方依赖。只需要 下载对应平台的二进制包,解压并且添加基本的配置即可正常启动 Prometheus Server。

3.2 下载 Prometheus

Prometheus 下载地址:https://prometheus.io/download/

3.3 上传安装文件

scp prometheus-2.30.3.linux-amd64.tar.gz root@node2:/opt/

3.4 解压安装文件

# 解压
tar -zxvf prometheus-2.30.3.linux-amd64.tar.gz

# 改名
mv prometheus-2.30.3.linux-amd64 prometheus

3.5 修改配置文件

# 切换路径
cd prometheus
# 编辑配置文件
vim prometheus.yml

# 控制 Prometheus 服务器的全局配置
global:
  scrape_interval: 15s # 将抓取间隔设置为每 15 秒一次。 默认为每 1 分钟一次。
  evaluation_interval: 15s # 每 15 秒评估一次规则。 默认为每 1 分钟一次
  # scrape_timeout 设置为全局默认值(10 秒)。

# 警报配置
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# 规则配置文件
# 加载规则并根据全局 "evaluation_interval" 定期评估
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 配置采集目标相关, prometheus 监视的目标。
# Prometheus 自身的运行信息可以通过 HTTP 访问,所以 Prometheus 可以监控自己的运行数据。
scrape_configs:
  # 监控作业的名称 
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # 表示静态目标配置,就是固定从某个 target 拉取数据
    # 默认方案为 HTTP
    static_configs:
      - targets: ["localhost:9090"]

  # 添加如下 clickhouse 监控
  - job_name: "clickhouse"
    static_configs:
      - targets: ['node2:9363'] # 默认端口号为 9396,要跟 clickhouse 的配置相同

3.6 启动

# 前台启动
./prometheus --config.file=prometheus.yml

# 后台启动
nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

3.7 访问 webUI 页面

http://node2:9090

4. 安装Grafana

4.1 介绍

Grafana是一款用Go语言开发的开源数据可视化工具,可以做数据监控和数据统计,带有告警功能。目前使用grafana的公司有很多,如paypal、ebay、intel等。

4.2 下载安装文件

Grafana 下载地址:https://grafana.com/grafana/download

4.3 上传安装文件

scp grafana-enterprise-8.2.1.linux-amd64.tar.gz root@node2:/opt/

4.4 解压安装文件

bash

# 解压 
tar zxvf grafana-enterprise-8.2.1.linux-amd64.tar.gz

4.5 启动 Grafana

bash

# 转到 grafana 文件夹
cd grafana-8.2.1/

# 前台启动
bin/grafana-server web

# 后台启动
 nohup ./bin/grafana-server web > ./grafana.log 2>&1 &
4.6 打开 web UI

http://node2:3000

账号名与密码默认 admin

5. 配置Grafana

5.1 添加Prometheus数据源

5.2 配置 Dashboard

可以自己创建 Dashboard 添加需要监控的指标

但是手动添加指标太慢了,需要很久才能将所需的指标都添加完成,并且需要一定的经验,否则会遗漏一些重要指标,这里推荐使用clickhouse监控模板,可以到 https://grafana.com/dashboards 网站,找到大量可直接使用的 Dashboard 模板。

5.3 通过模板添加Dashboard

Grafana 中所有的 Dashboard 通过 JSON 进行共享,下载并且导入这些 JSON 文件,就可 以直接使用这些已经定义好的 Dashboard。

相关文章