How do you shard Prometheus scraping, and what do you lose?
AdvancedProductionScaling Prometheus, Long-Term Storage & HA
Answer
Use hashmod relabelling so each server keeps a subset of targets, or the Prometheus Operator shards field, which does the same automatically:
relabel_configs:
- source_labels: [__address__]
modulus: 4
target_label: __tmp_hash
action: hashmod
- source_labels: [__tmp_hash]
regex: "2"
action: keep
You lose a single query view and cross-shard recording rules/alerts. You need a query layer (Thanos Query, Mimir, Promxy) on top, and alert rules that need the global view must move there.
More on Scaling Prometheus, Long-Term Storage & HA
What are the practical limits of a single Prometheus server?IntermediateWhen does hierarchical federation still make sense?IntermediateCompare Thanos, Grafana Mimir and VictoriaMetrics.AdvancedThanos sidecar versus Thanos Receive: how do you choose?AdvancedWhat is Prometheus agent mode and when do you use it?IntermediateHow do you tune `remote_write` for high throughput?Advanced