官方介绍文档:
https://prometheus.io/docs/prometheus/latest/federation/
简介
在运维中,一个Prometheus服务节点所能接管的主机数量有限。而联邦模式允许 Prometheus 服务器从另一个 Prometheus 服务器抓取特定数据。有分层联邦和跨服务联邦,分层联邦较为常用,且配置简单。
分层联邦
配置
scrape_configs:
- job_name: 'federate'
scrape_interval: 15s #数据刮取间隔时间
honor_labels: true ##为true表示可避免监控指标冲突
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{job=""}' ##此处引号中填入每个prometheus服务中的job名称,名字可采用模糊匹配。
例如prometheus1中有node_exporter的监控job名host1,prometheus2中有host2。
分别填入后prometheus主节点上便可获取两个prometheus服务上主机的信息。
static_configs:
- targets:
- 'prometheus-1ip:9090'
- 'prometheus-2ip:9090'
- 'prometheus-3ip:9090'
###注意###
建议在全局变量配置中修改scrape_timeout时间,默认10s,当每个prometheus服务都含有大量服务器时,必须延长该时间,否则会出现错误。
例
使用联邦后可任意查看不同prometheus服务上的job,比如利用node_exporter可以查看不同系统主机的性能,以及系统整体的资源使用情况。