Long-Term Storage
Thanos, Mimir, VictoriaMetrics, and global views
Plain Prometheus keeps weeks of data on one local disk. Eventually you'll want things it can't give you: a year of history for capacity planning, one query across twenty clusters, and storage that survives losing a machine. Three open-source projects dominate this space. They all speak PromQL, so Grafana and your queries barely change.
The shared idea
All of them separate the jobs Prometheus does on one machine:
- Ingest: Prometheus keeps scraping, or runs as an agent.
- Store: blocks go to object storage (S3, GCS, Azure Blob, SeaweedFS), which is cheap, durable, and effectively unlimited.
- Query: a stateless query layer fans out across recent data and object storage, deduplicates HA pairs, and merges the results.
- Compact and downsample: background jobs merge blocks and create 5-minute and 1-hour resolution copies for fast long-range queries.
This works so neatly because Prometheus blocks are immutable directories (see Head, WAL & Blocks). Uploading a finished 2-hour block to S3 is just copying files; nothing ever needs to be updated in place.
Thanos
Thanos bolts onto existing Prometheus servers.
| Component | Job |
|---|---|
| Sidecar | Runs next to each Prometheus; uploads finished blocks to object storage and serves recent data to queries |
| Store Gateway | Serves historical blocks from object storage |
| Querier | Fans out PromQL to sidecars and stores, deduplicates replicas by the replica label |
| Compactor | Compacts and downsamples blocks in the bucket; applies retention |
| Ruler | Evaluates rules against the global view |
| Receive | Optional remote-write ingestion instead of sidecars |
Its strength is incrementalism: keep every Prometheus as it is, add a sidecar, and you get a global query view and unlimited retention.
Grafana Mimir
Mimir (descended from Cortex) is a horizontally scalable, multi-tenant
remote-write backend. Prometheus servers, or agents, remote_write
into it; it shards series across ingesters, replicates them 3x, and
flushes blocks to object storage.
- Built for very large scale (hundreds of millions of series) and many tenants with per-tenant limits.
- Runs as microservices or a single "monolithic" binary for smaller setups.
- Includes a ruler and Alertmanager, so alerting can be centralized too.
VictoriaMetrics
A separate implementation of a Prometheus-compatible TSDB, known for low
resource usage and operational simplicity. Single-node mode is one
binary that accepts remote write (and many other protocols) and can
replace Prometheus storage entirely; cluster mode splits insert, select,
and storage. Its query language, MetricsQL, is a PromQL superset with a
few semantic differences (for example, in how rate() handles window
edges), worth knowing before porting alerts.
Choosing
| If you... | Consider |
|---|---|
| Have a few Prometheus servers and want history and a global view with minimal change | Thanos with sidecars |
| Need a central multi-tenant platform for many teams, at large scale | Mimir |
| Want the simplest, cheapest single-node long-term store | VictoriaMetrics single-node |
| Don't want to operate any of it | A managed service (Grafana Cloud, Amazon/Google/Azure managed Prometheus) |
| Have one cluster and 30 days is enough | Nothing. Plain Prometheus. |
Don't add a long-term storage layer until you have a concrete need for it. Each of these is a distributed system with its own failure modes, capacity planning, and on-call burden. A single Prometheus with 30 days of retention and an HA twin covers a surprising number of organisations.
Downsampling, honestly
Long-term stores keep 5-minute and 1-hour downsampled data so a one-year graph doesn't load billions of raw samples. Two consequences:
- You can't see short spikes in old data. A 30-second outage last March is invisible in 1-hour resolution.
- Downsampled data stores aggregates (min, max, sum, count, counter) per
interval, so
rate()still works on it, but the window must be at least a few times the resolution.rate(x[5m])on 1-hour data returns nothing.
A sketch with this repo
The repo's SeaweedFS module provides an S3-compatible
object store, so a natural extension is a Thanos sidecar next to the
prometheus service, writing blocks to a SeaweedFS bucket:
thanos-sidecar:
image: quay.io/thanos/thanos:<version>
command:
- sidecar
- --tsdb.path=/prometheus
- --prometheus.url=http://prometheus:9090
- --objstore.config-file=/etc/thanos/bucket.yml # type: S3, endpoint: host.docker.internal:8333
volumes:
- prometheus_data:/prometheus # shares the TSDB volumeplus a querier and store gateway. Prometheus needs
--storage.tsdb.min-block-duration=2h and
--storage.tsdb.max-block-duration=2h so it never compacts blocks
itself, because the Thanos compactor does that in the bucket.
That's a good capstone extension, now that the SeaweedFS module exists.