娃哈哈好喝-真的!
技术够用就行,吃好喝好睡好!

prometheus+grafana监控clickhouse

prometheus+grafana监控clickhouse

1、配置clickhouse

1.1、clickhouse已经安装好了,需要配置一下默认的用户名和密码,在users.xml配置文件中

[root@test clickhouse-server]# pwd
/etc/clickhouse-server
[root@test clickhouse-server]# ls
config.d config.xml users.d users.xml

找到<users> <default>标签,clickhouse不建议使用明文密码,所以要将password标签改为password_sha256_hex:

<!--密码为123456 -->
<password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>

生成密文密码方式:

[root@test clickhouse-server]# echo -n 123456 | openssl dgst -sha256
(stdin)= 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
[root@test clickhouse-server]#

1.2、更改监听地址

默认clickhouse只监听本地ip端口,需要根据实际需要修改,这里改成监听所有ip

[root@test clickhouse-server]# pwd
/etc/clickhouse-server
[root@test clickhouse-server]# ls
config.d config.xml users.d users.xml

修改config.xml文件,找到如下标签改成0.0.0.0

<listen_host>0.0.0.0</listen_host>

重启clickhouse

2、配置clickhouse_exporter

下载地址:https://github.com/ClickHouse/clickhouse_exporter

clickhouse_exporter是go语言写的,所以编译前需要有go语言环境

[root@test dl]# yum -y install golang
[root@test dl]# ls
clickhouse_exporter-master.zip clickhouse_exporter-master
[root@test dl]# cd clickhouse_exporter-master/
[root@test clickhouse_exporter-master]# ls
clickhouse_exporter.go docker             Dockerfile go.mod LICENSE   README.md
CONTRIBUTING.md         docker-compose.yml exporter   go.sum Makefile VERSION
[root@test clickhouse_exporter-master]# go build clickhouse_exporter.go
go: downloading github.com/prometheus/client_golang v0.8.0
go: downloading github.com/prometheus/log v0.0.0-20151026012452-9a3136781e1f
go: downloading github.com/Sirupsen/logrus v1.0.1
go: downloading github.com/prometheus/common v0.0.0-20170707053319-3e6a7635bac6
go: downloading github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a
go: downloading github.com/golang/protobuf v0.0.0-20170712042213-0a4f71a498b7
go: downloading github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612
go: downloading github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.0
[root@test clickhouse_exporter-master]# ls
clickhouse_exporter     CONTRIBUTING.md docker-compose.yml exporter go.sum   Makefile   VERSION
clickhouse_exporter.go docker           Dockerfile         go.mod   LICENSE README.md
[root@test clickhouse_exporter-master]#

编译成功后会得到这个文件:clickhouse_exporter

这个文件就是我们需要使用到的,可以将它复制到/usr/bin/下

clickhouse_exporter功能:

[root@test clickhouse_exporter-master]# ./clickhouse_exporter -h
Usage of ./clickhouse_exporter:
 -clickhouse_only
      Expose only Clickhouse metrics, not metrics from the exporter itself
 -insecure
      Ignore server certificate if using https (default true)
 -log.level value
      Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal, panic].
 -scrape_uri string
      URI to clickhouse http endpoint (default "http://localhost:8123/")
 -telemetry.address string
      Address on which to expose metrics. (default ":9116")
 -telemetry.endpoint string
      Path under which to expose metrics. (default "/metrics")
[root@test clickhouse_exporter-master]#

启动clickhouse_exporter

[root@test ~]# clickhouse_exporter -scrape_uri http://default:[email protected]:8123/

default是默认用户名,如果没有可以不写,但是有些版本不写会报错,所以这里还是配置了

查看监听端口

[root@test ~]# netstat -tunlap| grep 9116
tcp6 0 0 :::9116 :::* LISTEN 77096/./clickhouse_
tcp6 0 0 172.20.20.163:9116 172.20.20.169:64689 ESTABLISHED 77096/./clickhouse_
[root@test ~]#

3、配置prometheus

在prometheus.yml文件中添加如下配置项:

  - job_name: "clickhouse"
metrics_path: '/metrics'
static_configs:
- targets: ['172.20.20.163:9116']
#如果有多台监控目标可以这样写
- job_name: "clickhouse"
metrics_path: '/metrics'
static_configs:
- targets:
- '172.20.20.163:9116'
- '172.20.20.164:9116'
- '172.20.20.165:9116'

clickhouse_exporter默认使用的是9116端口

修改完重启prometheus

4、配置grafnana

首先添加prometheus的数据源,这里掠过,接下来添加clickhouse的监控面板

直接导入面板编号882

赞(0)
未经允许不得转载:娃哈哈好喝 » prometheus+grafana监控clickhouse
分享到: 更多 (0)