本次基于docker来实现对clickhouse的指标的监控,需安装三个软件
- Granfa
- prometheus
- clickhouse-export
准备docker环境和docker-compose编排
1、首先安装Granfa
# 获取镜像
docker pull grafana/grafana
# 后台启动容器,将23000映射到容器的3000
docker run -d -p 23000:3000 --name=my-grafana -v /data/grafana:/var/lib/grafana grafana/grafana
注意: 需要对/data/grafana进行权限赋予
chmod 777 /data/grafana
2、通过docker-compose方式来安装prometheus、clickhouse-export
version: '3'
services:
prometheus:
image: prom/prometheus:latest
restart: always
network_mode: host ##网络类型为主机
user: root
container_name: prometheus
ports: ##开放端口
- "9091:9090"
depends_on: ##
- clickhouse-exporter
volumes: ###挂载目录,注意启动此文件之前要新建此标签下的目录权限异常的需赋777权限(prometheus.yml需要手动创建,后续将介绍)
- /data/clickHouse_docker/docker-compose/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- /data/clickHouse_docker/docker-compose/prometheus/prometheus-data:/prometheus
clickhouse-exporter:
image: f1yegor/clickhouse-exporter:latest
restart: always
network_mode: host
container_name: clickhouse-exporter
ports:
- 9116:9116
environment:
###此处写CK的user和password,注意不要加空格
- CLICKHOUSE_USER=username
- CLICKHOUSE_PASSWORD=password
####此处为命令行启动docker时添加的参数,即和docker run xxxx -scrape_url=//xxx.xxx.xxx.xxx:xxxx等价
###写CK的host:port
command: -scrape_uri=http://xxxx:8123
手动创建prometheus.yml文件:
vim /data/clickHouse_docker/docker-compose/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['172.19.19.xx:9090']
- job_name: 'clickhouse_exporter'
scrape_interval: 5s
static_configs:
#下面填写前面的yml文件定义的 clickhouse_exporter的端口
- targets: ['172.19.19.xx:9116']
通过docker-compose方式启动已经编排好的yml
启动命令
docker-compose up -d
或者
docker-compose -f xxx.yml文件名