移動(dòng)網(wǎng)站制作價(jià)格安裝百度到手機(jī)桌面
一、概述
監(jiān)控是運(yùn)維的一大利器,要想運(yùn)維好clickhouse,首先就要對(duì)其進(jìn)行監(jiān)控,clickhouse有幾種監(jiān)控?cái)?shù)據(jù)的方式,一種是系統(tǒng)本身監(jiān)控,一種是通過exporter來監(jiān)控,下面分別描述一下
二、系統(tǒng)自帶監(jiān)控
我下面會(huì)對(duì)監(jiān)控做一些介紹,詳細(xì)可查看官網(wǎng)
1.配置數(shù)據(jù)采集
修改配置文件/etc/clickhouse-server/config.xml使其可以往prometheus寫數(shù)據(jù)
<clickhouse><listen_host>0.0.0.0</listen_host><http_port>8123</http_port><tcp_port>9000</tcp_port><prometheus><endpoint>/metrics</endpoint><port>9363</port><metrics>true</metrics><events>true</events><asynchronous_metrics>true</asynchronous_metrics></prometheus>
</clickhouse>
查看metrics數(shù)據(jù)
curl 127.0.0.1:9363/metrics
2.配置prometheus和grafana
2.1安裝prometheus和grafana
prometheus和grafana的啟動(dòng)可查看這個(gè)文章
2.2修改prometheus配置文件
# 控制 Prometheus 服務(wù)器的全局配置
global:scrape_interval: 15s # 將抓取間隔設(shè)置為每 15 秒一次。 默認(rèn)為每 1 分鐘一次。evaluation_interval: 15s # 每 15 秒評(píng)估一次規(guī)則。 默認(rèn)為每 1 分鐘一次# scrape_timeout 設(shè)置為全局默認(rèn)值(10 秒)。# 警報(bào)配置
alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# 規(guī)則配置文件
# 加載規(guī)則并根據(jù)全局 "evaluation_interval" 定期評(píng)估
rule_files:# - "first_rules.yml"# - "second_rules.yml"# 配置采集目標(biāo)相關(guān), prometheus 監(jiān)視的目標(biāo)。
# Prometheus 自身的運(yùn)行信息可以通過 HTTP 訪問,所以 Prometheus 可以監(jiān)控自己的運(yùn)行數(shù)據(jù)。
scrape_configs:# 監(jiān)控作業(yè)的名稱 - job_name: "prometheus"# metrics_path defaults to '/metrics'# 表示靜態(tài)目標(biāo)配置,就是固定從某個(gè) target 拉取數(shù)據(jù)# 默認(rèn)方案為 HTTPstatic_configs:- targets: ["localhost:9090"]# 添加如下 clickhouse 監(jiān)控- job_name: "clickhouse"static_configs:- targets: ['127.0.0.1:9363']- targets: ['192.168.1.2:9363']- targets: ['192.168.1.3:9363']
2.3 導(dǎo)入grafana模版
導(dǎo)入grafana面板,可以從官網(wǎng)中找合適的面板,親測(cè)如果只使用clickhouse的內(nèi)部監(jiān)控,不基于exporter,14192的面板比較合適
- 添加文件夾
- 添加面板
- 選擇面板號(hào)或直接導(dǎo)入json文件
這樣一套基于clickhouse的監(jiān)控就處理好了
三、基于exporter的監(jiān)控
clickhouse_exporter詳情可以通過github來進(jìn)行查看,exporter只能用于舊的ClickHouse版本,現(xiàn)代版本嵌入了Prometheus端點(diǎn),安裝go的方式可以看這篇文章
# 安裝go環(huán)境,使用如下安裝方式安裝的是go1.6版本,編譯會(huì)報(bào)錯(cuò),需要安裝高版本的go(應(yīng)該大于1.13版本即可),我使用的是1.21的版本
apt-get install golang# 下載代碼
git clone https://github.com/ClickHouse/clickhouse_exporter.git
# 進(jìn)入到目錄
cd clickhouse_exporter
# 編譯
go build clickhouse_exporter.go
# 啟動(dòng)exporter
nohup ./clickhouse_exporter &
只下來就可以按照上面的步驟來配置了,可以應(yīng)用882模版,也可以在已有的dashboard中配置一些我們需要的查詢
加上對(duì)應(yīng)的query后apply即可
告警指標(biāo)可以參考騰訊云的指標(biāo)