prometheus联邦集群

 

目录

一:联邦集群

二:什么时候会用到联邦集群

1)跨数据中心

2)垮服务

三:prometheus配置文件解析

1) 整体配置文件

2)scrape_configs

四:prometheus部署联邦集群

1)prometheus 主server和prometheus联邦分别部署prometheus

2) 配置联邦节点到node节点抓取数据


一:联邦集群

二:什么时候会用到联邦集群

1)跨数据中心

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

  

2)垮服务

同一服务器里不同的服务监控指标用不同的prometheus联邦节点收集监控数据

例如,一个运行多种服务的集群调度器可以暴露在集群上运行的服务实例的资源使用信息(例如内存和 CPU 使用率)。另一方面,运行在集群上的服务只需要暴露指定应用程序级别的服务指标。通常,这两种指标集分别被不同的 Prometheus 服务器抓取。利用联邦,监控服务级别指标的 Prometheus 服务器也可以从集群中 Prometheus 服务器拉取其特定服务的集群资源使用率指标,以便可以在该 Prometheus 服务器中使用这两组指标集

三:prometheus配置文件解析

1) 整体配置文件

# 全局配置global:
  # 默认抓取周期,可用单位ms、smhdwy #设置每15s采集数据一次,默认1分钟
  [ scrape_interval: <duration> | default = 1m ]
  # 默认抓取超时
  [ scrape_timeout: <duration> | default = 10s ]
  # 估算规则的默认周期 # 每15秒计算一次规则。默认1分钟
  [ evaluation_interval: <duration> | default = 1m ]
  # 和外部系统(例如AlertManager)通信时为时间序列或者警情(Alert)强制添加的标签列表
  external_labels:
    [ <labelname>: <labelvalue> ... ]
 
# 规则文件列表
rule_files:
  [ - <filepath_glob> ... ]
 
# 抓取配置列表
scrape_configs:
  [ - <scrape_config> ... ]
 
# Alertmanager相关配置
alerting:
  alert_relabel_configs:
    [ - <relabel_config> ... ]
  alertmanagers:
    [ - <alertmanager_config> ... ]
 
# 远程读写特性相关的配置
remote_write:
  [ - <remote_write> ... ]
remote_read:
  [ - <remote_read> ... ]

2)scrape_configs

一个scrape_config 片段指定一组目标和参数, 目标就是实例,指定采集的端点, 参数描述如何采集这些实例, 主要参数如下

scrape_interval: 抓取间隔,默认继承global值。
scrape_timeout: 抓取超时时间,默认继承global值。
metric_path: 抓取路径, 默认是/metrics
scheme: 指定采集使用的协议,http或者https,默认为http
params: 指定url参数。
basic_auth: 指定认证信息。
*_sd_configs: 指定服务发现配置
static_configs: 静态指定服务job。
relabel_config: relabel设置。

四:prometheus部署联邦集群

1)prometheus 主server和prometheus联邦分别部署prometheus

在三个prometheus节点同时执行

[root@prometheus-1 prometheus-2.36.2.linux-amd64]# pwd
/opt/prometheus/prometheus-2.36.2.linux-amd64

#创建prometheus连接
ln -sv /opt/prometheus/prometheus-2.36.2.linux-amd64 /opt/prometheus/prometheus

#添加prometheus启动脚本
vi /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/opt/prometheus/prometheus/
ExecStart=/opt/prometheus/prometheus/prometheus --config.file=/opt/prometheus/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target

#启动prometheus
systemctl restart prometheus

#添加开机启动
systemctl enable prometheus


2) 配置联邦节点到node节点抓取数据

联邦集群1 收集node1的数据

#编辑prometheus.yaml文件添加下面node1节点监控信息

vi prometheus.yml


- job_name: "prometheus-node1"
    static_configs:
      - targets: ["10.19.14.9:9100"]

联邦集群2 收集node2的数据

#编辑prometheus.yaml文件添加下面node2节点监控信息

vi prometheus.yml


- job_name: "prometheus-node2"
    static_configs:
      - targets: ["10.19.14.21:9100"]

prometheus server 收集联邦节点

# 添加以下配置,增加联邦集群节点  到prometheus server节点。
 
   - job_name: 'prometheus-federate-2.61'
     scrape_interval: 10s
     honor_labels: true   #保持原标签不变
     metrics_path: '/federate'
     params:
      'match[]':
       - '{job="prometheus"}'
       - '{__name__=~"job:.*"}'
       - '{__name__=~"node.*"}'
     static_configs:
     - targets: ["10.19.2.61:9090"]

   - job_name: 'prometheus-federate-2.62'
     scrape_interval: 10s
     honor_labels: true
     metrics_path: '/federate'
     params:
      'match[]':
       - '{job="prometheus"}'
       - '{__name__=~"job:.*"}'
       - '{__name__=~"node.*"}'
     static_configs:
     - targets: ["10.19.2.62:9090"]




#检查配置文件语法
./promtool check config ./prometheus.yml

#重启prometheus
systemctl restart prometheus

  • 31
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Prometheus联邦集群部署文档 一、简介 Prometheus联邦集群可以实现多个Prometheus实例之间的数据共享和查询,解决了单个Prometheus实例面对大规模监控数据的性能瓶颈和数据管理问题。本文档将介绍如何部署Prometheus联邦集群。 二、前置条件 1.已经安装了Prometheus。 2.所有Prometheus实例的版本必须相同。 3.所有Prometheus实例的配置文件必须相同。 4.所有Prometheus实例的时间必须同步。 5.所有Prometheus实例的数据存储位置必须相同。 三、部署步骤 1.编辑Prometheus配置文件,添加联邦配置 在每个Prometheus实例的配置文件中添加如下配置: ``` remote_write: - url: "http://prometheus1.example.com:9090/api/v1/write" - url: "http://prometheus2.example.com:9090/api/v1/write" ``` 其中,url为其他Prometheus实例的remote_write地址。 2.重启Prometheus实例 在每个Prometheus实例上执行以下命令: ``` systemctl restart prometheus ``` 3.配置Prometheus实例的查询端点 在每个Prometheus实例的配置文件中添加如下配置: ``` remote_read: - url: "http://prometheus1.example.com:9090/api/v1/read" - url: "http://prometheus2.example.com:9090/api/v1/read" ``` 其中,url为其他Prometheus实例的remote_read地址。 4.重启Prometheus实例 在每个Prometheus实例上执行以下命令: ``` systemctl restart prometheus ``` 5.验证联邦集群配置 在每个Prometheus实例的Web界面上,点击“Status” => “Federation”,可以看到联邦集群的状态信息。 四、总结 通过以上步骤,可以创建Prometheus联邦集群,实现多个Prometheus实例之间的数据共享和查询。但需要注意的是,联邦集群配置的正确性和性能取决于网络和存储的性能,因此需要进行充分的测试和调优。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值