參考:https://blog.51cto.com/lee90/2062252
官網對於聯邦的介紹:https://prometheus.io/docs/prometheus/latest/federation/
prometheus2.0 在參數上有原先的1.X有較大的變化,很多參數被去掉了。另外優化了CPU占用、存儲空間占用等,具體可以看官方文檔。
這里貼一下prometheus2.0的聯邦(又稱Shard)搭建方法,一些理論知識就不貼了,自己去google扒吧:
官網對於聯邦的介紹:https://prometheus.io/docs/prometheus/latest/federation/
聯邦有不同的用例。它通常用於實現可擴展的prometheus,或者將metrics從一個服務的prometheus拉到另一個Prometheus上用於展示。
分層聯邦:
分層聯邦允許普羅米修斯擴展到數十個數據中心和數百萬個節點的環境。在這種用例中,聯邦拓撲類似於一棵樹,更高級別的普羅米修斯服務器從大量的從屬服務器收集匯總的時間序列數據。
跨服務聯邦:
In cross-service federation, a Prometheus server of one service is configured to scrape selected data from another service's Prometheus server to enable alerting and queries against both datasets within a single server.
在跨服務聯合中,一個服務的普羅米修斯服務器被配置為從另一個服務的普羅米修斯服務器中刮取選定的數據,以使得能夠針對單個服務器內的兩個數據集進行警報和查詢。
For example, a cluster scheduler running multiple services might expose resource usage information (like memory and CPU usage) about service instances running on the cluster. On the other hand, a service running on that cluster will only expose application-specific service metrics. Often, these two sets of metrics are scraped by separate Prometheus servers. Using federation, the Prometheus server containing service-level metrics may pull in the cluster resource usage metrics about its specific service from the cluster Prometheus, so that both sets of metrics can be used within that server.
例如,運行多個服務的集群調度程序可能會暴露有關在集群上運行的服務實例的資源使用情況信息(如內存和CPU使用情況)。另一方面,在該群集上運行的服務將僅公開特定於應用程序的服務度量標准。通常,這兩套指標是由單獨的普羅米修斯服務器來抓取的。使用聯邦,包含服務級別度量的普羅米修斯服務器可以從集群普羅米修斯拉入有關其特定服務的集群資源使用度量,以便這兩組度量可以在該服務器內使用。
【舉個例子:我們要監控mysqld的運行狀態,可以使用1個主Prometheus+2個分片Prometheus(一個用來采集node_exporter的metrics、一個用來采集mysql_exporter的metrics),然后在主Prometheus上做匯總】
安裝prometheus和mysqld_exporter、postgres_exporter的步驟也不寫了,很簡單的,exporter的部署我們通常用ansible或saltstack之類的工具批量分發。
我這里實驗起見,在一台機器上跑了3個shard節點,1個global節點。
Node1: 10.0.20.25 (跑了老版本的prometheus1.7、mysql_exporter、postgres_exporter,這是之前做實驗搭建的環境)
Node2: 10.0.20.26 (跑了prometheus2.0、mysql_exporter、postgres_exporter)
以下內容,請參考原文https://blog.51cto.com/lee90/2062252