I have 3 Prometheus servers and want to consolidate all of them
into 1 Grafana. And one VM (Server C) is in a restricted zone and
this zone only allows a special firewall rule from this zone to
other zones.
Prometheus A pulls (receives) metrics from Prometheus B
In this scenario, we use the
Federation
feature to pull metrics from another Prometheus. You don't need to
make any changes to Prometheus B, just add a new job to
prometheus.yml of Prometheus A.
Please check lines 13~15, you can only pull some metrics you need.
Prometheus C pushes (forwards) metrics to Prometheus A
In this scenario, you first need to enable the
Remote Write Receiver
feature in Prometheus A. You just need to add
--web.enable-remote-write-receiver to your
docker-compose.yml, no need to modify
prometheus.yml
1# prometheus.yml of A 2prometheus: 3image:prom/prometheus:latest 4container_name:prometheus 5expose: 6- 9090 7ports: 8- 9090:9090 9volumes:10- /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro11- /opt/prometheus/web.yml:/etc/prometheus/web.yml:ro12command:13- '--config.file=/etc/prometheus/prometheus.yml'14- '--web.config.file=/etc/prometheus/web.yml'15- '--web.enable-remote-write-receiver'
Then, you need to modify docker-compose.yml and
*prometheus.yml of Prometheus C. First, you need to enable
Prometheus agent
mode, just need to add --enable-feature=agent to
docker-compose.yml.
1# docker-compose.yml of C 2prometheus: 3image:prom/prometheus:latest 4container_name:prometheus 5expose: 6- 9090 7ports: 8- 9090:9090 9volumes:10- /opt/grafana/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro11command:12- '--config.file=/etc/prometheus/prometheus.yml'13- '--enable-feature=agent'14- '--log.level=debug'
Second, you need to edit prometheus.yml, add the
remote_write section, and enter the URL of Prometheus A in it.
1# prometheus.yml of C2global:3scrape_interval:15s45remote_write:6- url:'http://(Domain of Prometheus A):9090/api/v1/write'7basic_auth:8username:'******'9password:'******'
Sanity check: you can enable the log to debug level and check that
it's sending the data.