背景描述
当采集指标过多时,超过单个 prometheus 的处理能力,我们通常会采用多个 prometheus 实例分别采集一定的指标分片,然后通过 thanos 做聚合,对外提供统一查询服务。
本文通过简单的实验,演示 thanos 的分片数据采集与聚合查询能力,架构如下:

实验假设存在两个 prometheus 实例,分别采集不同的监控指标分片,prometheus 实例均通过 remote write 方式将数据写入 thanos receiver。receiver 采用多副本方式运行,并通过 hashring 方式实现将不同租户的数据写入不同的 receiver 实例,即 receiver 01 和 receiver 02 存储来自 prometheus foo 的监控指标数据,而 receiver 03 和 receiver 04 存储来自 prometheus bar 的监控指标数据,最后通过 thanos query 聚合多个 receiver 的数据,提供统一查询接口。
实验验证
本文基于 docker 方式启动 prometheus 以及 thanos,需要在机器上预装 docker。 Ubuntu 或 CentOS 环境,可以通过如下命令一件安装:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
1. 部署 Prometheus 实例
# cat << EOF > prometheus-foo-conf.yaml
global:
scrape_interval: 5s
external_labels:
cluster: foo
replica: 0
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9090']
remote_write:
- url: 'http://127.0.0.1:10908/api/v1/receive'
headers:
THANOS-TENANT: foo
EOF
# docker run -d --net=host --rm \
-v $(pwd)/prometheus-foo-conf.yaml:/etc/prometheus/prometheus.yaml \
-u root \
--name prometheus-foo \
quay.io/prometheus/prometh

本文详细介绍了如何通过分片部署多个Prometheus实例,配合Thanos接收器和查询器,实现数据的高效聚合查询。通过实例展示如何配置Prometheus、ThanosReceiver和ThanosQuery,以及如何根据租户信息实现数据负载均衡,以增强监控系统的扩展性和性能。
最低0.47元/天 解锁文章
1471

被折叠的 条评论
为什么被折叠?



