
Thanos 高可用 PrometheusPB级监控数据方案专栏监控 可观测性难度专家标签ThanosPrometheus高可用长期存储对象存储前言单机 Prometheus 存在两个根本限制存储容量上限和单点故障。Thanos 解决了这两个问题是大规模监控的标准方案。一、Thanos 架构Prometheus多副本 ↓ Thanos Sidecar数据上传 对象存储S3/OSS/COS← 长期存储无限容量 ↑ Thanos Store读取历史数据 ↑ Thanos Query全局统一查询入口 ↑ Grafana二、部署 Thanos Sidecar# 和Prometheus同pod部署# Thanos sidecar配置thanos sidecar\--tsdb.path/prometheus\--prometheus.urlhttp://localhost:9090\--grpc-address0.0.0.0:10901\--http-address0.0.0.0:10902\--objstore.config-file/etc/thanos/bucket.yml# bucket.yml阿里云OSS示例type: OSS config: endpoint:oss-cn-hangzhou-internal.aliyuncs.combucket:monitoring-thanosaccess_key_id:YOUR_AKaccess_key_secret:YOUR_SK三、Thanos Query全局查询# 聚合多个Prometheus数据源thanos query\--grpc-address0.0.0.0:10901\--http-address0.0.0.0:9090\--storeprometheus-1:10901\--storeprometheus-2:10901\--storethanos-store:10901\--query.replica-labelreplica# 去重多副本相同数据四、数据降采样Compactor# Thanos Compactor 对老数据做降采样减少存储空间thanos compact\--data-dir/var/thanos/compact\--objstore.config-file/etc/thanos/bucket.yml\--retention.resolution-raw30d# 原始精度保留30天--retention.resolution-5m180d# 5min精度保留180天--retention.resolution-1h365d# 1h精度保留1年五、多集群查询# 在Thanos Query Federation中聚合多集群指标# 每个K8s集群部署独立Prometheus Sidecar# Thanos Query向所有集群的Sidecar查询# Grafana连接统一的Thanos Query入口# 使用external_labels区分不同集群# prometheus.ymlglobal: external_labels: cluster:prod-cluster-01region:cn-hangzhou结语Thanos 让 Prometheus 从单机工具变成了企业级监控平台。关键是理解数据流Sidecar 负责把本地数据上传到对象存储Query 负责统一查询接口。