<p>We have several clusters where our applications are running. We would like to set up a Central Monitoring cluster which can scrape metrics from rest of cluster using Prometheus Federation.</p>

<p>So to do that, I need to install prometheus server in each of cluster and install prometheus server via federation in central cluster.I will install Grafana as well in central cluster to visualise the metrics that we gather from rest of prometheus server.</p>

<p>So the question is;</p>

<ol>
<li><p>Where should I setup the Alert Manager? Only for Central Cluster or each cluster has to be also alert manager?</p></li>
<li><p>What is the best practice alerting while using Federation?</p></li>
<li><p>I though ı can use ingress controller to expose each prometheus server? What is the best practice to provide communication between prometheus server and federation in k8s?</p></li>
</ol>

semural
<p>Based on this <a href="https://www.robustperception.io/federation-what-is-it-good-for" rel="nofollow noreferrer">blog</a></p>
<blockquote>
<p>Where should I setup the Alert Manager? Only for Central Cluster or each cluster has to be also alert manager?</p>
<p>What is the best practice alerting while using Federation?</p>
</blockquote>
<p>The answer here would be to do that on each cluster.</p>
<blockquote>
<p>If the data you need to do alerting is moved from one Prometheus to another then you've added an additional point of failure. This is particularly risky when WAN links such as the internet are involved. As far as is possible, you should try and push alerting as deep down the federation hierarchy as possible. For example an alert about a target being down should be setup on the Prometheus scraping that target, not a global Prometheus which could be several steps removed.</p>
</blockquote>
<hr />
<blockquote>
<p>I though ı can use ingress controller to expose each prometheus server? What is the best practice to provide communication between prometheus server and federation in k8s?</p>
</blockquote>
<p>I think that depends on use case, in each doc I checked they just use targets in <code>scrape_configs.static_configs</code> in the prometheus.yml</p>
<hr />
<p>like <a href="https://prometheus.io/docs/prometheus/latest/federation/#configuring-federation" rel="nofollow noreferrer">here</a></p>
<pre><code>scrape_configs:
  - job_name: 'federate'
    scrape_interval: 15s

    honor_labels: true
    metrics_path: '/federate'

    params:
      'match[]':
        - '{job=&quot;prometheus&quot;}'
        - '{__name__=~&quot;job:.*&quot;}'

    static_configs:
      - targets:
        - 'source-prometheus-1:9090'
        - 'source-prometheus-2:9090'
        - 'source-prometheus-3:9090'
</code></pre>
<hr />
<p><strong>OR</strong></p>
<hr />
<p>like <a href="https://developers.mattermost.com/blog/cloud-monitoring/" rel="nofollow noreferrer">here</a></p>
<pre><code>prometheus.yml:
    rule_files:
      - /etc/config/rules
      - /etc/config/alerts

    scrape_configs:
      - job_name: 'federate'
        scrape_interval: 15s

        honor_labels: true
        metrics_path: '/federate'

        params:
          'match[]':
            - '{job=&quot;prometheus&quot;}'
            - '{__name__=~&quot;job:.*&quot;}'

        static_configs:
          - targets:
            - 'prometheus-server:80'
</code></pre>
<hr />
<p>Additionally, worth to check how they did this in this <a href="https://developers.mattermost.com/blog/cloud-monitoring/" rel="nofollow noreferrer">tutorial</a>, where they used <a href="https://helm.sh/" rel="nofollow noreferrer">helm</a> to build central monitoring cluster with two prometheus servers on two clusters.</p>
<p><a href="https://i.stack.imgur.com/ybdMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ybdMe.png" alt="enter image description here" /></a></p>
