Retention & Capacity
Estimating disk and memory before you need them
Prometheus fails in predictable ways when it runs out of resources: it runs out of memory when there are too many active series, and out of disk when retention and ingestion outgrow the volume. Both are easy to estimate in advance.
Retention
Two flags, and whichever limit is reached first wins:
--storage.tsdb.retention.time=15d # default 15d
--storage.tsdb.retention.size=5GB # default unlimitedRetention deletes whole blocks, so data disappears in block-sized
steps, and the size limit counts blocks plus WAL plus head chunks. Set
retention.size to about 80% of the volume as a safety net: if
ingestion suddenly doubles, Prometheus deletes old data early instead of
filling the disk and crashing.
Estimating disk
disk ≈ retention_seconds × samples_per_second × bytes_per_sample
samples_per_second = active_series / scrape_interval_seconds
bytes_per_sample ≈ 1-2 (measure yours, below)
Example: 1,000,000 series, 15s interval, 15 days, 1.5 B/sample
samples/s = 1,000,000 / 15 ≈ 66,700
disk = 1,296,000 s × 66,700 × 1.5 B ≈ 130 GB
+ WAL and head chunks (a few GB) + ~20% headroom -> ~160 GB volumeMeasure your actual bytes per sample:
rate(prometheus_tsdb_compaction_chunk_size_bytes_sum[1d])
/ rate(prometheus_tsdb_compaction_chunk_samples_sum[1d])Disk grows linearly with scrape frequency. Moving from 15s to 5s triples storage. Scrape fast only where it's useful.
Estimating memory
Memory is dominated by the head block, so it scales with active series, plus series churned in the last couple of hours (see Cardinality Management):
memory ≈ active_series × ~3-4 KB + query load + Go GC headroom
1,000,000 series -> roughly 4-8 GB resident in practiceGo's garbage collector by default lets the heap grow to twice the live
set before collecting, so the actual RSS can be much higher than the
live data. Prometheus 3 sets GOMEMLIMIT from the container's memory
limit automatically, which makes the GC work harder as it approaches
the limit instead of letting the container be OOM-killed.
Queries cost memory too. A query that touches a million series over a day loads every one of those samples. Guard rails:
--query.max-samples=50000000 # abort queries that would load more samples (default 50M)
--query.timeout=2m # abort slow queries
--query.max-concurrency=20 # queue extra queriesWatch process_resident_memory_bytes{job="prometheus"} against the
container's limit, and alert at ~80%. When Prometheus is OOM-killed it
restarts, replays the WAL (which itself needs memory), may be
OOM-killed again, and can loop. Find the cardinality source before
just adding RAM.
CPU
CPU goes to three things: decoding scrapes (scales with samples per second), compaction (bursts every 2 hours), and queries, which are usually the most variable. A server ingesting 100k samples/s with light query load is comfortable on 2-4 cores. Recording rules count as query load, since they're queries that run every interval.
Inputs to a capacity plan
# active series, and growth over the past week
prometheus_tsdb_head_series
prometheus_tsdb_head_series - prometheus_tsdb_head_series offset 1w
# ingestion rate
rate(prometheus_tsdb_head_samples_appended_total[5m])
# biggest jobs
topk(10, sum by (job) (scrape_samples_post_metric_relabeling))
# current disk
prometheus_tsdb_storage_blocks_bytes + prometheus_tsdb_wal_storage_size_bytesLab: plan this stack
- Run the four queries above and note the numbers.
- Measure bytes per sample (it may need a few hours of data and a block or two before the compaction metrics appear).
- Calculate how much disk 15 days of retention needs at today's
ingestion rate. Compare it with the
5GBsize limit incompose_prod.yaml. Which limit would apply first? - Now imagine scaling the demo app to 50 instances. What changes, and by how much?