最新消息:

Thanos-Prometheus的扩展好伙伴

IT技术 ipcpu 3245浏览 0评论

一、Thanos概述:

Thanos主要用于解决大规模prometheus部署、增强prometheus高可用的工具。

项目地址
https://github.com/thanos-io/thanos

二、Thanos架构

从官方github中可以看到Thanos的架构图,我就不贴了,我画了一个更简单的图。

我们来说下相关的组件:

thanos-sidecar: 使用Sidecar方式与Prometheus连接,主要有两个功能:一是上传Prometheus的Block数据到云端的对象存储;二是提供GRPC接口给Query组件查询使用。

thanos-query: 查询其他组件的grpc接口获取数据,并对数据进行聚合去重处理。

thanos-store: 对接云端的对象存储进行查询,提供GRPC接口供Query组件调用

thanos-compact: 图上没有画。对存储在云端对象存储中的数据进行合并压缩和降采样(DownSample)。可以减少云端存储内容和空间。我们没有使用,因为我们没有降采样需求,单纯压缩合并数据降不了多少存储成本。

thanos-rule: 图上没有画。设定规则查询query组件,若触发告警,则通知altermanager。仅当监控数据需要合并查询时才需要开启,否则直接使用prometheus的rule就可以。

三、Thanos解决了什么问题

3.1 监控数据上传到云端对象存储

我们知道Prometheus官方不推荐在本地存储长时间的数据(也存在文件打开过多的风险),我们曾经存储过半年的数据,每一次重启Prometheus加载历史数据都是痛苦的等待,需要20-30分钟,在这期间监控都无法正常工作。尽管Prometheus有remote write等功能,但是成本低廉的云端对象存储确是个好办法。

3.2 功能强大的Query组件


Query组件拥有去重合并功能,为分片设计的Prometheus提供了一个很好的汇聚查询点。例如腾讯云的Kvaas分片工具也使用了Query组件的查询功能。

四、部署

部分组件的启动脚本如下

# Sidecar
ExecStart=/data/apps/promes/thanos/thanos sidecar \
          --tsdb.path=/data/apps/promes/prometheus/data \
          --prometheus.url=http://localhost:9090 \
          --objstore.config-file=/data/apps/promes/thanos/objstore.yml \
          --http-address=0.0.0.0:10901 \
          --grpc-address=0.0.0.0:10902

# Store
ExecStart=/data/apps/promes/thanos/thanos store \
          --data-dir=/data/apps/promes/thanos/store-cache \
          --objstore.config-file=/data/apps/promes/thanos/objstore.yml \
          --http-address=0.0.0.0:10905 \
          --grpc-address=0.0.0.0:10906 

# Query
ExecStart=/data/apps/promes/thanos/thanos query \
          --http-address=0.0.0.0:10903 \
          --grpc-address=0.0.0.0:10904 \
          --store=10.140.100.6:10902 \
          --store=10.140.100.6:10906 \
          --store=172.28.9.46:10902 \
          --store=172.28.9.46:10906 \
          --query.replica-label=replica

五、Thanos常见问题答疑

5.1 Thanos-Query的去重功能

很多人都有这个疑惑,比如PromA、PromB两个prometheus同时采集相同的监控数据(假如入库时间戳不一样,采集到的数据也略有差别);Thanos-Query同时配置PromA和PromB为查询数据源,会查到两份数据么?
不会。这也是Thanos-Query去重功能,实现方式是:

遍历所有 series, 去掉每个 series 中包含的特定 replicaLabel(比如多副本时, 每个副本都有一个自己的标签); 
如果去掉特殊标签后的多个 series 的标签对是一样的, 即认为是重复的, 去掉只留其一。

这个功能特点,可以让我们在数据中心部署2份一模一样的Prometheus互为备份,使用Thanos-Query查询去重(⭐⭐⭐)。

5.2 Thanos能解决分片问题么?

Thanos没有提供Prometheus分片方案,可以使用手动定义分片、hashmod、KvaaS来分片。

5.3 Thanos有没有遇到什么坑?

sidecar存活,但是prometheus挂掉或者正在重启状态,这种情况会导致这台Prometheus的最近2小时数据查询不到。
Query组件存活,但是后端挂载的store组件或者sidecar组件挂掉,可能会导致查询数据不全。
这两种情况都必须加强对于监控

#组件本身healthy和ready监控
thanos_status{check="healthy",component="query"} 1
thanos_status{check="ready",component="query"} 1
thanos_status{check="healthy",component="sidecar"} 1
thanos_status{check="ready",component="sidecar"} 1
thanos_status{check="healthy",component="store"} 1
thanos_status{check="ready",component="store"} 1
#sidecar组件中prometheus是否存活
thanos_sidecar_prometheus_up 1
#query组件后端数量
thanos_store_nodes_grpc_connections{external_labels="{dc=\"AB\"}",store_type="sidecar"} 1
thanos_store_nodes_grpc_connections{external_labels="{dc=\"AB\"}",store_type="store"} 1
#store组件载入的block数量
thanos_bucket_store_blocks_loaded 1498

参考资料

https://thanos.io/tip/components/rule.md/
https://huajiaaa.com/2020/11/22/thanos-Querier/

转载请注明:IPCPU-网络之路 » Thanos-Prometheus的扩展好伙伴

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 另外还发现过一次文件打开数不足的问题。too many open files。监控组件还是要把打开数设置大一些。
    ipcpu2年前 (2021-10-08)Reply