一、安裝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 下載
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