Introduction

A highly available, long-term storage layer for Prometheus

Component

Component Role
Sidecar Runs next to Prometheus, uploads blocks to object storage, provides StoreAPI for Querier
Store Gateway Reads historical blocks from object storage, exposes them via StoreAPI
Querier Aggregates metrics from multiple Prometheus / Store Gateways, provides single query endpoint
Compactor Deduplicates and compacts metric blocks, reduces storage usage
Ruler Evaluates Prometheus-style recording and alert rules on long-term data

Setup compose.yml

services:
  minio:
    image: minio/minio:latest
    container_name: minio
    environment:
      MINIO_ROOT_USER: minio
      MINIO_ROOT_PASSWORD: minio123
    command: server /data
    ports:
      - "9000:9000"
    volumes:
      - minio_data:/data
      
  # Run Thanos Sidecar next to Prometheus
  # It uploads Prometheus blocks to object storage and exposes StoreAPI
  thanos-sidecar:
    image: thanosio/thanos:latest
    container_name: thanos-sidecar
    command:
      - sidecar
      - --tsdb.path=/prometheus
      - --prometheus.url=http://prometheus:9090
      - --objstore.config-file=/etc/thanos/bucket.yml
      - --http-address=0.0.0.0:10902
      - --grpc-address=0.0.0.0:10901
    volumes:
      - ./bucket.yml:/etc/thanos/bucket.yml
      - prometheus_data:/prometheus
    depends_on:
      - prometheus
    ports:
      - "10901:10901"  # gRPC
      - "10902:10902"  # HTTP
      
  # Compacts and deduplicates HA metrics 
  # Used if have multiple Prometheus HA
  thanos-compact:
    image: thanosio/thanos:latest
    container_name: thanos-compact
    command:
      - compact
      - --data-dir=/thanos-compact
      - --objstore.config-file=/etc/thanos/bucket.yml
    volumes:
      - ./bucket.yml:/etc/thanos/bucket.yml
      - thanos_compact:/thanos-compact
      
  # Reads historical blocks from object storage 
  # Exposes StoreAPI for Querier
  thanos-store:
    image: thanosio/thanos:latest
    container_name: thanos-store
    command:
      - store
      - --objstore.config-file=/etc/thanos/bucket.yml
      - --grpc-address=0.0.0.0:10901
      - --http-address=0.0.0.0:10902
    volumes:
      - ./bucket.yml:/etc/thanos/bucket.yml
    ports:
      - "10911:10901"
      - "10912:10902"

	# Querier aggregates metrics from:
	# 1. Live Prometheus (Sidecar)
	# 2. Historical Store Gateway
  thanos-querier:
    image: thanosio/thanos:latest
    container_name: thanos-querier
    command:
      - query
      - --http-address=0.0.0.0:10902
      - --store=thanos-sidecar:10901
      - --store=thanos-store:10901
    ports:
      - "10902:10902"

bucket.yml

type: S3
config:
  bucket: "thanos-bucket"
  endpoint: "minio:9000"
  access_key: "minio"
  secret_key: "minio123"
  insecure: true