前言
随着项目组陆续上线, 监控也出现了分类的情况。 A项目组用Prom B项目组用蓝鲸,C项目组也用了Prom.
每个项目组的监控都是独立出来的, 如果需要查询某个项目的监控内容,则需要登录到不同的页面,不同的账号密码。
管理起来非常混乱。所以,我们需要将项目的监控数据整合起来。而Prome的联邦集群,则可以将多地域的数据集中到一起。
环境准备
我们假设,目前有2个业务。其中一个业务为:AAA,另一个是BBB. AAA业务单独Prome,而BBB业务为了监控高可用做了两台,并且两个业务分别在 EU区域和NA区域, 那我们就需要三台监控节点分别如下:
| 区域 |
业务 |
副本ID |
IP |
| EU |
AAA |
0 |
192.168.1.68 |
| NA |
BBB |
0 |
192.168.1.68 |
| NA |
BBB |
1 |
192.168.1.68 |
配置文件
让我们来生成配置文件prometheus-EU.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| global: scrape_interval: 15s evaluation_interval: 15s external_labels: zone: eu business: AAA replica: 0
scrape_configs: - job_name: 'prometheus' metrics_path: /metrics scheme: http static_configs: - targets: ['localhost:9090']
|
prometheus-00-NA.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| global: scrape_interval: 15s evaluation_interval: 15s external_labels: zone: na business: BBB replica: 0
scrape_configs: - job_name: 'prometheus' metrics_path: /metrics scheme: http
static_configs: - targets: ['localhost:9090'] - job_name: 'node' static_configs: - targets: ['192.168.1.68:9100', '192.168.1.34:9273']
|
prometheus-01-NA.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| global: scrape_interval: 15s evaluation_interval: 15s external_labels: zone: na business: BBB replica: 1
scrape_configs: - job_name: 'prometheus' metrics_path: /metrics scheme: http
static_configs: - targets: ['localhost:9090']
- job_name: 'node' static_configs: - targets: ['192.168.1.68:9100', '192.168.1.34:9273']
|
启动节点
prometheus-eu
1 2 3 4 5 6 7
| docker run \ -d --rm \ -p 9090:9090 \ -v $(pwd)/prometheus-EU.yml:/etc/prometheus/prometheus.yml \ -v $(pwd)/prometheus-EU-data/:/prometheus \ --name prometheus-eu \ prom/prometheus
|
prometheus-00-na
1 2 3 4 5 6 7
| docker run \ -d --rm \ -p 9091:9090 \ -v $(pwd)/prometheus-00-NA.yml:/etc/prometheus/prometheus.yml \ -v $(pwd)/prometheus-00-NA-data/:/prometheus \ --name prometheus-00-na \ prom/prometheus
|
prometheus-01-na
1 2 3 4 5 6 7
| docker run \ -d --rm \ -p 9092:9090 \ -v $(pwd)/prometheus-01-NA.yml:/etc/prometheus/prometheus.yml \ -v $(pwd)/prometheus-01-NA-data/:/prometheus \ --name prometheus-01-na \ prom/prometheus
|
主节点
prometheus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| global: scrape_interval: 15s evaluation_interval: 15s
scrape_configs: - job_name: 'federate' scrape_interval: 15s
honor_labels: true metrics_path: '/federate'
params: 'match[]': - '{job="prometheus"}' - '{__name__=~"job:.*"}'
static_configs: - targets: - '192.168.1.68:9090' - '192.168.1.68:9091' - '192.168.1.68:9092'
|
运行节点
1 2 3 4 5 6 7
| docker run \ -d --rm \ --net host \ -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \ -v $(pwd)/prometheus/:/prometheus \ --name prometheus-federate \ prom/prometheus
|



我们可以看到, 联邦集群有一个问题,他只会去抓取节点的数据, 但是并不会去主动处理重复的数据.
如上图, 我们需要看某业务下的节点状态,但是缺出现重复的数据。