prometheus+grafana监控clickhouse


一、安装Prometheus

1.1 下载

官网地址

wget https://github.com/prometheus/prometheus/releases/download/v2.29.1/prometheus-2.29.1.linux-amd64.tar.gz
tar -xf prometheus-2.29.1.linux-amd64.tar.gz

1.2 修改配置

配置文件: prometheus.yml 

# my global config
global:
  scrape_interval:     15s # 全局的采集间隔,默认是 1m,这里设置为 15s
  evaluation_interval: 15s # 全局的规则触发间隔,默认是 1m,这里设置 15s


scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'StarRocks_Cluster01' # 每一个集群称之为一个job,可以自定义名字作为StarRocks集群名
    metrics_path: '/metrics'    # 指定获取监控项目的Restful Api

    static_configs:
      - targets: ['fe_host1:http_port','fe_host3:http_port','fe_host3:http_port']
        labels:
          group: fe # 这里配置了 fe 的 group,该 group 中包含了 3 个 Frontends

      - targets: ['be_host1:webserver_port', 'be_host2:webserver_port', 'be_host3:webserver_port']
        labels:
          group: be # 这里配置了 be 的 group,该 group 中包含了 3 个 Backends
  - job_name: 'StarRocks_Cluster02' # 可以在Prometheus中监控多个StarRocks集群
    metrics_path: '/metrics'

    static_configs:
      - targets: ['fe_host1:http_port','fe_host3:http_port','fe_host3:http_port']
        labels:
          group: fe

      - targets: ['be_host1:webserver_port', 'be_host2:webserver_port', 'be_host3:webserver_port']
        labels:
          group: be

1.3 启动服务

该命令将后台运行 Prometheus,并指定其 web 端口为 9090。启动后,即开始采集数据,并将数据存放在 ./data 目录中

nohup ./prometheus --config.file="./prometheus.yml" --web.listen-address=":9090" --log.level="info" &

1.4 访问

地址:http://prometheus_host:prometheus_port(9090)

 

二、安装Grafana

2.1 下载

Grafana官网

wget https://dl.grafana.com/oss/release/grafana-8.0.6.linux-amd64.tar.gz
tar -zxf grafana-8.0.6.linux-amd64.tar.gz

 

2.2 修改配置

配置文件: {grafana_home}/conf/defaults.ini 

注意:①使用默认配置既可;②默认http端口3000;③默认用户名/密码为admin/admin

 

2.3开启服务

nohup ./bin/grafana-server --config=./conf/defaults.ini &

 

三、安装vertamedia-clickhouse-datasource插件

3.1 在线安装

grafana-cli plugins install vertamedia-clickhouse-datasource

注:速度极其慢,放弃

 

3.2 离线安装

插件文档

 

3.3 旧版本(<=2.2.0)

3.3.1 下载

  地址:https://grafana.com/api/plugins/vertamedia-clickhouse-datasource/versions/2.1.0/download

3.3.2 上传

  目录: {grafana_home}/data/plugins 

3.3.3 解压

unzip Vertamedia-clickhouse-grafana-2.1.0-0-gbcee398.zip

mv Vertamedia-clickhouse-grafana-2.1.0-0-gbcee398 vertamedia-clickhouse-datasource

 

3.3.4 允许未签名插件

  注意:①2.2.0版本之前未提供签名,因此需要修改配置文件 {grafana_home}/conf/defaults.ini 

[plugins]
allow_loading_unsigned_plugins=vertamedia-clickhouse-datasource

 

3.4 新版本(>2.2.0)

3.4.1 下载

  地址:https://grafana.com/api/plugins/vertamedia-clickhouse-datasource/versions/2.3.1/download

  或

   wget https://github.com/Vertamedia/clickhouse-grafana/releases/download/v2.3.1/vertamedia-clickhouse-datasource-2.3.1.zip 

3.4.2 上传

  目录: {grafana_home}/data/plugins

3.4.3 解压

unzip vertamedia-clickhouse-datasource-2.3.1.zip

mv vertamedia-clickhouse-datasource-2.3.1 vertamedia-clickhouse-datasource

 

3.5 重启Grafana

# 关闭当前服务
ps -ef | grep grafana

kill -p {pid}

# 重新启动服务
nohup ./bin/grafana-server --config=./conf/defaults.ini &

 

3.6 访问web

地址:http://grafana_host:grafana_port(默认3000)

 

四、Clickhouse集群

4.1 开启prometheus接口

配置文件: /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>

 

4.2 开启日志查询

配置文件: users.xml 

注意:users.xml文件,在profiles中加入<log_queries>1</log_queries>

<log_queries>1</log_queries>

 

4.3 重启集群

systemctl restart clickhouse-server

 

五、添加监控

5.1 修改prometheus配置

注意:targets默认端口9363

 

5.2 重启prometheus

# 关闭当前服务
ps -ef | grep grafana

kill -p {pid}

# 重新启动服务
nohup ./prometheus --config.file=./prometheus.yml --web.listen-address=:19090 --log.level=info &
# 或者 通过热加载方式重启,如果返回Lifecycle API is not enabled,那么就是启动的时候没有开启热更新,需要在启动的命令行增加参数: --web.enable-lifecycle
curl -X POST http://prometheus_host:prometheus_port/-reload

 

 六、配置dashboard

6.1 导入模板

https://grafana.com/grafana/dashboards/13606

https://grafana.com/grafana/dashboards/2515

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM