1. Prometheus联邦集群
https://prometheus.io/docs/prometheus/latest/federation/
1.1 介绍
Pormetheus Federation(联邦)机制是 Promehteus 本身提供的一种集群化的扩展能力。当我们要监控的服务很多的时候,我们会部署很多的 Prometheus 节点分别 Pull 这些服务暴露的 Metrics,Federation 机制可以讲这些分别部署的 Prometheus 节点所获得的指标聚合起来,存放在一个中心点的 Prometheus。
1.2 作用
如果prometheus需要采集的服务器过多,会导致prometheus server节点压力过大,降低服务器性能。为了分担server节点的压力,可以配置prometheus联邦集群。 Prometheus联邦集群通过设置多个prometheus联邦从节点采集服务器数据,然后再将联邦节点的数据汇总到prometheus联邦server主节点。server主节点负责接收联邦节点数据,而采集服务器数据的任务则是由联邦节点完成,这样就可以分担server节点的压力。
1.3 环境配置
ip | 描述 |
---|---|
10.103.236.199 | Prometheus Server,node_exporter |
10.103.236.20 | Prometheus Federation |
10.103.236.21 | Prometheus Federation |
2. Prometheus部署
2.1 所有节点部署
2.2 聚合节点
- 10.103.236.199
yml
scrape_configs:
- job_name: 'federate'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
# 通过 match 参数,配置要拉取的 Metrics,
# 不要 Pull full metrics
params:
'match[]':
- '{job="prometheus"}'
- '{job="node"}'
- '{job="blackbox"}'
static_configs:
# 其他 Prometheus 节点
- targets:
- 'prometheus-follower-1:9090'
- 'prometheus-follower-2:9090'
scrape_configs:
- job_name: 'federate'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
# 通过 match 参数,配置要拉取的 Metrics,
# 不要 Pull full metrics
params:
'match[]':
- '{job="prometheus"}'
- '{job="node"}'
- '{job="blackbox"}'
static_configs:
# 其他 Prometheus 节点
- targets:
- 'prometheus-follower-1:9090'
- 'prometheus-follower-2:9090'
2.3 Federation01
- 10.103.236.20
2.4 Federation02
- 10.103.236.20