1. Préparer Prometheus #
Les prérequis indispensables.
Réglages obligatoires #
- Labels externes uniques par Prometheus (
cluster,replica) : indispensables pour la déduplication et l'identification. - Compaction locale désactivée :
--storage.tsdb.min-block-duration=2het--storage.tsdb.max-block-duration=2h(le compactor Thanos s'en charge). - Rétention locale courte (quelques jours) : l'historique est dans l'objet.
- API d'administration et lifecycle pour que le sidecar recharge la configuration.
# prometheus.yml
global:
scrape_interval: 15s
external_labels:
cluster: prod-eu
replica: A
scrape_configs:
- job_name: prometheus
static_configs: [{ targets: ["localhost:9090"] }]
- job_name: node
static_configs: [{ targets: ["node-exporter:9100"] }]prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--storage.tsdb.min-block-duration=2h \
--storage.tsdb.max-block-duration=2h \
--storage.tsdb.retention.time=2d \
--web.enable-lifecycle --web.enable-admin-apiErreur Courante : Ne laissez jamais deux Prometheus avec exactement les mêmesexternal_labelsen dehors dereplica: Thanos ne pourrait plus distinguer les sources et dupliquerait ou fusionnerait mal les blocs.
2. Lancer le sidecar #
Avec son fichier de stockage objet.
Configuration et commande #
# bucket.yml (stockage objet partagé par tous les composants Thanos)
type: S3
config:
bucket: thanos
endpoint: minio:9000
access_key: minio
secret_key: minio123
insecure: truethanos sidecar \
--tsdb.path=/prometheus \
--prometheus.url=http://localhost:9090 \
--objstore.config-file=/etc/thanos/bucket.yml \
--grpc-address=0.0.0.0:10901 \
--http-address=0.0.0.0:109023. Stack Docker Compose complète #
Prometheus, sidecar et MinIO.
docker-compose.yml #
services:
minio:
image: quay.io/minio/minio
command: server /data --console-address ":9001"
environment: { MINIO_ROOT_USER: minio, MINIO_ROOT_PASSWORD: minio123 }
ports: ["9000:9000", "9001:9001"]
minio-init:
image: quay.io/minio/mc
depends_on: [minio]
entrypoint: ["sh", "-c", "sleep 5 && mc alias set l http://minio:9000 minio minio123 && mc mb -p l/thanos"]
prometheus:
image: prom/prometheus:latest
user: root
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.min-block-duration=2h
- --storage.tsdb.max-block-duration=2h
- --web.enable-lifecycle
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prom-data:/prometheus
ports: ["9090:9090"]
sidecar:
image: quay.io/thanos/thanos:latest
command:
- sidecar
- --tsdb.path=/prometheus
- --prometheus.url=http://prometheus:9090
- --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
- prom-data:/prometheus
depends_on: [prometheus, minio]
volumes: { prom-data: {} }4. Vérifier #
Le bloc est-il arrivé dans le bucket ?
Contrôles #
# Attendre ~2 h (ou forcer un bloc : curl -X POST localhost:9090/api/v1/admin/tsdb/snapshot)
docker compose run --rm --entrypoint sh quay.io/minio/mc -c "mc alias set l http://minio:9000 minio minio123 && mc ls l/thanos/"
thanos tools bucket ls --objstore.config-file=bucket.yml
thanos tools bucket inspect --objstore.config-file=bucket.yml
curl -s localhost:10902/metrics | grep -E 'thanos_shipper_uploads_total|thanos_sidecar_prometheus_up'Bonne Pratique : Sithanos_shipper_uploads_totalreste à 0, vérifiez d'abord que la compaction locale est bien désactivée et que le sidecar voit le même répertoire/prometheusque Prometheus.
