美文网首页
图解 prometheus 联邦制

图解 prometheus 联邦制

作者: vonhng | 来源:发表于2019-10-06 18:05 被阅读0次

prometheus 的联邦制分为两种,分层联邦和跨服务联邦。

1. 分层联邦

分层联邦允许 Prometheus 能够扩展到十几个数据中心和上百万的节点。在此场景下,联邦拓扑类似一个树形拓扑结构,上层的 Prometheus 服务器从大量的下层 Prometheus 服务器中收集和汇聚的时序数据。

例如,一个联邦设置可能由多个数据中心中的 Prometheus 服务器和一套全局 Prometheus 服务器组成。每个数据中心中部署的 Prometheus 服务器负责收集本区域内细粒度的数据(实例级别),全局 Prometheus 服务器从这些下层 Prometheus 服务器中收集和汇聚数据(任务级别),并存储聚合后的数据。这样就提供了一个聚合的全局视角和详细的本地视角。

分层联邦

2. 跨服务联邦

在跨服务联邦中,一个服务的 Prometheus 服务器被配置来提取来自其他服务的 Prometheus 服务器的指定的数据,以便在一个 Prometheus 服务器中对两个数据集启用告警和查询。

例如scene1,监控服务级别指标的 Prometheus 服务器也可以从集群中 Prometheus 服务器拉取其特定服务的集群资源使用率指标,以便可以在该 Prometheus 服务器中使用这两组指标集。

跨服务联邦场景 1

另外,如 scene2,运行在集群上的服务只需要暴露指定应用程序级别的服务指标,这些指标集分别被不同的 Prometheus 服务器抓取。

跨服务联邦场景 2

2.1. 实例

source prometheus 上部署有 node_exporter 服务,prometheus 配置如下


global:

  scrape_interval: 15s

  external_labels:

    monitor: 'codelab-monitor'

scrape_configs:

  - job_name: 'prometheus'

    scrape_interval: 15s

    static_configs:

      - targets: ['localhost:9090']

  - job_name: 'node_exporter'

    scrape_interval: 15s

    static_configs:

      - targets: ['localhost:9100']

service prometheus 从 source prometheus 上拿取 node_exporter 的数据


global:

  scrape_interval: 15s

  evaluation_interval: 15s

# alert 配置项,也可以在 source 端配置

alerting:

  alertmanagers:

  - static_configs:

    - targets:

      # - alertmanager:9093

# 告警规则文件

rule_files:

  # - "first_rules.yml"

  # - "second_rules.yml"

scrape_configs:

  - job_name: 'federate'

    scrape_interval: 15s

    honor_labels: true  # 不覆盖源服务器公开的任何标签

    metrics_path: '/federate'

    params:

        'match[]':

            #- '{job="prometheus"}'  # 去除 source 端 prometheus 状态的指标

            - '{job="node_exporter"}'

            #- '{__name__=~"job:.*"}'

    static_configs:

    - targets: 

        - 'slave_ip1:9090'  #  source 端 pronetheus 启动地址,可以配置多个 source

        - 'slave_ip2:9090' 

2.1.1. 运行结果

分别启动 source prometheus 和 service prometheus,而后进入 http://service_ip:9090 查看结果,发现服务正常且能查询到 source 上的数据。

查询 node_exporter 采集结果 targets 状态

参考文档

1. https://www.yangcs.net/prometheus/3-prometheus/federation.html

2. https://prometheus.io/docs/prometheus/latest/federation/

相关文章

网友评论

      本文标题:图解 prometheus 联邦制

      本文链接:https://www.haomeiwen.com/subject/xanupctx.html