Thanos vs VictoriaMetrics
兩者都解決「Prometheus 不能水平擴展」的問題,但設計哲學不同。 以下以實際在做的場景為例:10 個 AWS Region、~75K samples/sec、~4.9M active series 的中央化監控架構。 重點不在 $/月,而在維運複雜度——這才是真正燒工程時間的地方。
一句話差異
| Thanos | VictoriaMetrics | |
|---|---|---|
| 設計哲學 | Prometheus 的擴充層(sidecars + object storage) | 從頭設計的 TSDB,相容 Prometheus API |
| 長期儲存 | S3 / GCS / Azure Blob(必須) | EBS 或本地磁碟 (S3 可選) |
| 遷移方式 | 官方推薦:每個 Region 加 Sidecar container | 推薦:Prometheus remote_write(只改 config) |
| RAM 效率 | 與 Prometheus 相當 | 社群基準測試普遍宣稱顯著低於 Prometheus(見下方 RAM 段落,數字需以自身環境驗證) |
| PromQL 相容性 | 完整(本身就是 Prometheus 生態) | 99% 相容 + MetricsQL 擴充 |
元件數量比較(官方文件的事實基礎)
Thanos 必要元件
根據 Thanos 官方架構文件:
| 元件 | 角色 | 是否必要 |
|---|---|---|
| Sidecar | 上傳 blocks 到 S3、提供 local Prom 查詢 | ✅ 每個 Prometheus 都要(Sidecar 模式) |
| Query (Querier) | 查詢入口,fan-out 到 Store/Sidecar | ✅ 必要 |
| Store Gateway | 從 S3 讀歷史資料 | ✅ 必要 |
| Compactor | 壓縮 blocks、downsampling、retention | ⚠️ 基本查詢可省,但生產必備 |
| Receive | 替代 Sidecar 的 push 模式 | ⚠️ 可選(與 Sidecar 二擇一) |
| Ruler | 中央執行 recording/alerting rules | ⚠️ 可選 |
| Query Frontend | 查詢 cache + 分片 | ⚠️ 強烈建議(生產規模) |
生產規模最小配置:5 個元件(Sidecar/Query/Store/Compactor + Query Frontend)
VMCluster 必要元件
根據 VictoriaMetrics Cluster 官方文件:
"A minimal cluster must contain the following nodes: a single
vmstorage... a singlevminsert... a singlevmselect."
| 元件 | 角色 | 是否必要 |
|---|---|---|
| vmstorage | 儲存層、內建 merge/compaction | ✅ 必要 |
| vminsert | 寫入路由(stateless) | ✅ 必要 |
| vmselect | 查詢路由(stateless) | ✅ 必要 |
| vmagent | source 端 scraping / remote_write | ⚠️ 可選(用 Prometheus 也行) |
| vmalert | alerting rules | ⚠️ 可選 |
| vmauth | 認證/限流/路由 | ⚠️ 可選 |
生產規模最小配置:3 個元件
元件數差距:Thanos 約 1.7 倍 於 VMCluster。
架構模式比較
Thanos Sidecar 模式(官方推薦)
每個 Region EKS Pod:
┌────────────────────────────────────┐
│ container: prometheus (既有) │
│ container: thanos-sidecar (新增) │ ← 每個 Region manifest 都要改
└────────────────────────────────────┘
│ gRPC Store API (pull,非 push)
▼
Central:
Thanos Query ──▶ Thanos Store Gateway ──▶ S3 (long-term)
──▶ Sidecar gRPC (recent data)
Thanos Compactor(定期壓縮 S3 blocks)
資料流:
- 最近 2 小時的資料:Query 直接向各 Region 的 Sidecar 拉(gRPC)
- 超過 2 小時的資料:Sidecar 上傳到 S3,Query 透過 Store Gateway 讀取
- Compactor:定期把 S3 裡的小 block 合併壓縮,降低儲存和查詢成本
Thanos Receive 模式(較新)
每個 Region:
Prometheus ──remote_write──▶ Thanos Receive (central)
│
Thanos Query Frontend
Thanos Store Gateway
Thanos Compactor
S3
與 VictoriaMetrics 的架構類似,但元件更多。
VictoriaMetrics Cluster 模式
每個 Region(只改 prometheus.yml):
Prometheus ──remote_write──▶ vmauth (TLS + bearer token)
│
vminsert ×2 (stateless)
│
vmstorage ×3 (replicationFactor=2)
│
vmselect ×2 (stateless)
│
Central Grafana / vmalert
維運場景對比(這是真正的差距)
場景 1:擴容(增加儲存容量)
Thanos:
- S3 無限擴展,調整 lifecycle policy 或不動都可以
- ✅ 這是 Thanos 最大優勢
VMCluster:
- 增加 vmstorage 節點時,官方明說:
"When new
vmstoragenodes are added... only newly ingested data is distributed evenly among old and newvmstoragenodes, while historical data remains on the oldvmstoragenodes." — Cluster Resizing and Scalability - 等 retention 過期,或臨時把新寫入導到新節點、舊節點只服務查詢
- ⚠️ 可運作,但要規劃 retention 窗口
結論:純擴儲存 Thanos 完勝
場景 2:Compactor 故障
Thanos:
- 官方文件明說:
"Only one instance of Compactor may run against a single stream of blocks in a single object storage."
- 可以對「不同 stream」(用 external labels 分片)跑多 instance,但同一 stream 同時只能一個
- 並發跑同一 stream 會損毀資料(object storage 無一致性鎖)
- 已知問題:corrupted/incomplete block 會讓 compactor halt,需要手動清理
- Compactor 掛了:compaction 停止 → S3 small blocks 累積 → 查詢變慢、成本上升
VMCluster:
- vmstorage 內建 background merge,每個 storage node 獨立處理自己分片的資料
- 沒有「compactor 單點」這個概念
- 一個 vmstorage node 掛了不影響其他 node 的 merge