Infrastructure Monitoring with Thanos: Scalable Prometheus

When metrics are scattered across multiple Prometheus instances and storing them for more than a couple of months becomes costly, a single point of control is lost. We implement Thanos, which unifies data into a global view and moves long-term storage to object storage while preserving familiar PromQL. Our team delivers the project turnkey—from audit to support—ensuring a reliable and scalable solution.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Infrastructure Monitoring with Thanos: Scalable Prometheus

We often see this scenario: multiple Prometheus instances collecting metrics from different clusters, data centers, or cloud regions. There is no single point to query all data at once. And Prometheus retention is limited to local disk — storing metrics longer than a few months becomes expensive and inefficient. Meanwhile, load can reach 1 million metrics per second, and each Prometheus instance stores data locally, leading to duplication and increased costs.

Thanos solves both problems. It provides a single global view across many Prometheus instances and moves long-term metric storage to object storage (S3, GCS, Azure Blob). Thanos does not replace Prometheus; it complements it, preserving familiar PromQL and Grafana compatibility. In practice, this can reduce infrastructure costs by up to 40% through storage optimization and downsampling.

Our team has deployed Thanos on dozens of projects, from startups to large enterprise installations handling hundreds of thousands of metrics per second. Below is a practical breakdown of components, typical mistakes, and the deployment process.

Thanos Architecture: Components

Component Role Deployment
Sidecar Uploads completed blocks to storage + gRPC for fresh data Sidecar container in Prometheus pod
Store Gateway Reads historical data from object storage, caches indexes Separate StatefulSet
Querier Accepts PromQL queries, merges responses from Sidecar + Store, deduplicates Separate Deployment (can HPA)
Compactor Downsampling (5m/1h), applies retention policies Background Job or CronJob

Storage Comparison: Local Prometheus vs Thanos Object Storage

Parameter Prometheus (local) Thanos (object storage)
Raw retention ~15 days (typical) 30+ days
Storage cost High (SSD) Low (S3/object)
Downsampling No Yes (5m, 1h)
Global query No Yes (Querier)

Why Thanos Over Standalone Prometheus?

Prometheus is efficient for a single cluster or group of servers. As soon as a second Prometheus appears — for another region, project, or tenant isolation — you face the problem of "fragmented glasses." You have to switch between datasources in Grafana or write complex proxies. Thanos unifies all sources under a single Query endpoint, and global retention is configured once for all data. Our clients save up to 40% on metric storage costs thanks to downsampling and tiered retention.

Avoiding Data Duplication in Thanos

If Prometheus runs in HA (two instances with the same load), Thanos Querier will see duplicate time series. Deduplication is enabled with the flag --query.replica-label=prometheus_replica. But there is a condition: both Prometheus instances must have identical all external labels except the replica label. A typical mistake is different values for cluster or env. As a result, Querier treats them as different sources and does not deduplicate — you will see doubled values on graphs.

Example of correct configuration:

global:
  external_labels:
    cluster: production-eu
    env: production
    prometheus_replica: replica-0 # for second instance use replica-1

We recommend agreeing on the external_labels scheme for each Prometheus instance in advance and testing deduplication on staging.

Why Store Gateway Can Be Slow

Store Gateway caches only indexes, not the actual metrics. Without caching, a query for a month of data can be slow (up to 10 seconds). Optimal setting: --index-cache-size=512MB and deploy Redis or Memcached as a shared cache. This reduces latency by two to three times.

Bucket config with retention for downsampled data:

---
type: S3
config:
  bucket: metrics-thanos-prod
  endpoint: s3.eu-west-1.amazonaws.com
  retention:
    resolution_raw: 30d
    resolution_5m: 90d
    resolution_1h: 365d
---

Raw data (15-second intervals) is stored for 30 days — that's expensive. Downsampled to 5-minute and hourly resolutions are stored longer and cheaper. Queries for the last quarter work with 5m, for the year — with 1h.

Reducing Storage Costs with Thanos

Thanos uses downsampling: rarely requested old data is stored in aggregated form (5-minute or hourly resolution). This reduces storage volume by 10–20 times compared to raw data. For example, storing raw metrics for a year would take ~10 TB, while with downsampling — 500 GB. Plus tiered retention: raw — 30 days, 5m — 90 days, 1h — 365 days. Thus, 70% of data is stored in cheap object storage, yielding up to 40% savings. For scaling Prometheus, Thanos is indispensable: it allows combining metrics from different Kubernetes clusters into a single storage, providing Kubernetes monitoring in tenths of a second.

Thanos Ruler: Cross-Cluster Alerting

Thanos Ruler executes Prometheus recording and alerting rules, querying data through Querier. This enables cross-cluster rules that are unavailable in plain Prometheus:

groups:
  - name: cross-cluster.rules
    rules:
      - alert: ClusterHighMemoryUsage
        expr: |
          avg by (cluster) ( node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes ) < 0.15
        for: 10m

Such an alert fires when the average memory utilization across the entire cluster drops below 15%. In Prometheus, you would have to run a separate query to each instance.

Deployment Process: 5 Stages
  1. Audit — inventory of all Prometheus instances, label schemes, current retention.
  2. Design — choose object storage, external_labels scheme, retention plan.
  3. Sidecar deployment — install Thanos Sidecar alongside each Prometheus (Helm chart or manifests).
  4. Storage setup — create bucket, configure Store Gateway and Querier.
  5. Compaction and monitoring — launch Compactor, configure retention in storage, migrate Grafana datasources to Querier.

At each stage we perform testing: compare query results from Prometheus vs Thanos Querier — they must match for fresh data.

What's Included in Our Work

  • Documentation of the deployed architecture.
  • Access to Thanos Querier for all teams.
  • Engineer training on working with Thanos (basic queries, typical alerts).
  • Support during stabilization phase (2 weeks after deployment).

Our Expertise and Guarantees

We are a team of DevOps engineers with 10+ years of experience, certified in Kubernetes and AWS. We have completed over 50 monitoring projects on Prometheus/Thanos, including systems with >1 million metrics per second. We guarantee that query performance will not degrade and retention will become manageable.

Order a monitoring audit — it takes 1 hour. Contact us to develop a deployment plan for your infrastructure. Get a consultation on infrastructure monitoring — our experts will help you choose the optimal architecture.