prometheus幾種高可用架構介紹及聯邦架構部署


問題背景:單個prometheus性能到達瓶頸問題、多個prometheus-server數據匯總問題等

prometheus監控數據持久化

首先大家都知道prometheus是自帶數據存儲功能的。
優點是簡單易用,基本無需配置
缺點是:1、存在數據無法長久保存(尤其是頻繁變更的監控對象,監控對象變化,短時間內監控數據也會隨之丟失,如k8s等)
2、基於本地存儲的話,Prometheus監控系統擴展比較難
以上缺點可以配置遠程存儲解決,使用remote_write和remote_read這兩個接口,從第三方存儲服務中進行監控數據的讀寫

prometheus集群方案
這里有篇文章介紹了幾種prometheus的集群架構,可參考: https://zhuanlan.zhihu.com/p/86763004

方案一:
多個prometheus監控相同的對象。意思就是一台node在被兩台或兩台以上的prometheus同時監控
缺點:對於被監控端,可能會多出一倍或以上的查詢請求
優點:只要有一台prometheus還在運行,就不會影響監控

  方案二:

聯邦集群,prometheus數據層層往上匯聚(類似金字塔結構)
優點:數據匯總展示,prometheus-worker壓力較小,如合理規划可以分類監控,數據保留更靈活(參考https://zhuanlan.zhihu.com/p/86763004)
缺點:prometheus-primary壓力較大,可通過配置文件使不同的prometheus-primary收集不同類的監控數據(參考同上鏈接)
官網描述: https://prometheus.io/docs/prometheus/latest/federation/

  這里進行方案二+遠端存儲(influxdb)的集群架構實現

操作:
1、安裝prometheus
下載安裝包: https://prometheus.io/download/
解壓、安裝、配置成為系統服務(3台都操作)

  2、安裝influxdb(6.127)
yum install即可,因為是做測試,使用默認的配置文件直接啟動

create database "prometheus"
create retention policy "prometheus_retention" on "prometheus" duration 4w replication 1 default
show retention policies on prometheus 

創建數據庫

  默認數據保留策略為一周,可以新建保留策略

  獲取prometheus連接遠端存儲的一個插件
github地址: https://github.com/prometheus/prometheus/tree/master/documentation/examples/remote_storage/remote_storage_adapter
執行(此插件占用9201端口。注意紅框內容,根據自己實際內容進行更改)

nohup ./remote_storage_adapter --influxdb-url=http://127.0.0.1:8086/ --influxdb.database="prometheus" --influxdb.retention-policy=prometheus_retention &

3、修改prometheus-worker的prometheus.yml文件

 

 

 systemctl直接啟動prometheus即可

4、修改prometheus-primary的prometheus.yml文件

聯邦集群的核心就在於每一個Prometheus Server都包含一個用於獲取當前實例中監控樣本的接口/federate,對於prometheus-primary來說,從federate獲取數據跟從exporter獲取數據沒什么區別

math[]:表示你想獲取prometheus-worker里哪些job的數據,也可以使用正則匹配
honor_labels:配置true可以確保當采集到的監控指標沖突時,能夠自動忽略沖突的監控數據。如果為false時,prometheus會自動將沖突的標簽替換為exported_的形式。還可以添加標簽以區分不同的監控目標

systemctl啟動prometheus
網頁輸入ip:9090查看

 

 

  5、grafana展示
通過正常的dashboard導入或者自建圖表進行數據展示

 參考:https://prometheus.io/docs/prometheus/latest/federation/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM