prometheus 的聯(lián)邦制分為兩種蛔溃,分層聯(lián)邦和跨服務(wù)聯(lián)邦举畸。
1. 分層聯(lián)邦
分層聯(lián)邦允許 Prometheus 能夠擴(kuò)展到十幾個(gè)數(shù)據(jù)中心和上百萬(wàn)的節(jié)點(diǎn)涵防。在此場(chǎng)景下俄周,聯(lián)邦拓?fù)漕?lèi)似一個(gè)樹(shù)形拓?fù)浣Y(jié)構(gòu)星澳,上層的 Prometheus 服務(wù)器從大量的下層 Prometheus 服務(wù)器中收集和匯聚的時(shí)序數(shù)據(jù)疚顷。
例如,一個(gè)聯(lián)邦設(shè)置可能由多個(gè)數(shù)據(jù)中心中的 Prometheus 服務(wù)器和一套全局 Prometheus 服務(wù)器組成禁偎。每個(gè)數(shù)據(jù)中心中部署的 Prometheus 服務(wù)器負(fù)責(zé)收集本區(qū)域內(nèi)細(xì)粒度的數(shù)據(jù)(實(shí)例級(jí)別)腿堤,全局 Prometheus 服務(wù)器從這些下層 Prometheus 服務(wù)器中收集和匯聚數(shù)據(jù)(任務(wù)級(jí)別),并存儲(chǔ)聚合后的數(shù)據(jù)如暖。這樣就提供了一個(gè)聚合的全局視角和詳細(xì)的本地視角笆檀。
2. 跨服務(wù)聯(lián)邦
在跨服務(wù)聯(lián)邦中,一個(gè)服務(wù)的 Prometheus 服務(wù)器被配置來(lái)提取來(lái)自其他服務(wù)的 Prometheus 服務(wù)器的指定的數(shù)據(jù)盒至,以便在一個(gè) Prometheus 服務(wù)器中對(duì)兩個(gè)數(shù)據(jù)集啟用告警和查詢(xún)酗洒。
例如scene1
,監(jiān)控服務(wù)級(jí)別指標(biāo)的 Prometheus 服務(wù)器也可以從集群中 Prometheus 服務(wù)器拉取其特定服務(wù)的集群資源使用率指標(biāo)枷遂,以便可以在該 Prometheus 服務(wù)器中使用這兩組指標(biāo)集樱衷。
另外,如 scene2酒唉,運(yùn)行在集群上的服務(wù)只需要暴露指定應(yīng)用程序級(jí)別的服務(wù)指標(biāo)矩桂,這些指標(biāo)集分別被不同的 Prometheus 服務(wù)器抓取。
2.1. 實(shí)例
source prometheus 上部署有 node_exporter 服務(wù)黔州,prometheus 配置如下
global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 15s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
scrape_interval: 15s
static_configs:
- targets: ['localhost:9100']
service prometheus 從 source prometheus 上拿取 node_exporter 的數(shù)據(jù)
global:
scrape_interval: 15s
evaluation_interval: 15s
# alert 配置項(xiàng)耍鬓,也可以在 source 端配置
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# 告警規(guī)則文件
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: 'federate'
scrape_interval: 15s
honor_labels: true # 不覆蓋源服務(wù)器公開(kāi)的任何標(biāo)簽
metrics_path: '/federate'
params:
'match[]':
#- '{job="prometheus"}' # 去除 source 端 prometheus 狀態(tài)的指標(biāo)
- '{job="node_exporter"}'
#- '{__name__=~"job:.*"}'
static_configs:
- targets:
- 'slave_ip1:9090' # source 端 pronetheus 啟動(dòng)地址阔籽,可以配置多個(gè) source
- 'slave_ip2:9090'
2.1.1. 運(yùn)行結(jié)果
分別啟動(dòng) source prometheus 和 service prometheus流妻,而后進(jìn)入 http://service_ip:9090
查看結(jié)果,發(fā)現(xiàn)服務(wù)正常且能查詢(xún)到 source 上的數(shù)據(jù)笆制。
參考文檔
1. https://www.yangcs.net/prometheus/3-prometheus/federation.html