Thanos — Use case

Jan 8 · 2 min read

Thanos uses prometheus to new level. Prometheus is time series database with lower retention period.

Now demanding environments, it is very important to have long term storage. Thanos does solve this problem by allowing Object store connectors. As object store can be unlimited storage.

Thanos — Architecture


Prometheus 2.2+ is mendatory for the setup to work.

Installation steps:

1. Download latest binary of prometheus & thanos

tar -xvzf thanos*
tar -xvzf prom*
mv /usr/local/bin/prometheus /usr/local/bin/prometheus_old
rm -f /usr/local/bin/promtool
cp prom*/prometheus /usr/local/bin/prometheus
cp prom*/tsdb /usr/local/bin/tsdb
cp prom*/promtool /usr/local/bin/promtool

cp thanos*/thanos /usr/local/bin/thanos

2. Add external labels with git commit

scrape_interval: 15s
evaluation_interval: 15s
# scrape_timeout is set to the global default (10s).

name: environment
cluster: production
region: asia
cloud: gcp
project: my-project

Step2: Add thanos processes on prometheus server

Step2.1: Create Bucket File

Cat bucket.yml
type: GCS
bucket: “thanostest”

service_account: “my-project-ace639bd4d70.json”

Step2.2: Create GCS Bucket

gsutil mb -c standard -l us-east1 gs://thanostest — project=my-project

Step2.3: Create service account with storage bucket access

Cat my-project-ace639bd4d70.json
“type”: “service_account”,
“project_id”: “my-project”,
“private_key_id”: “ace639bd4d70882ab9a50523efc1ff5670bf6633”,
“private_key”: “ — — -BEGIN PRIVATE KEY — — -\n\n — — -END PRIVATE KEY — — -\n”,
“client_email”: “”,
“client_id”: “111579088233215168392”,
“auth_uri”: “",
“token_uri”: “",
“auth_provider_x509_cert_url”: “",
“client_x509_cert_url”: “"

Step2.4: Start Services on prometheus server

./prometheus \
— storage.tsdb.max-block-duration=2h \
— storage.tsdb.min-block-duration=2h \
— web.enable-lifecycle

Or Add parameters to existing command line

cat /usr/lib/systemd/system/prometheus.service | grep tsdb
ExecStart=/usr/local/bin/prometheus — web.external-url= — web.route-prefix=/ — config.file /opt/prometheusum/prometheus.yml — log.level=info — storage.tsdb.retention=15d — storage.tsdb.path /opt/ — storage.tsdb.max-block-duration=2h — storage.tsdb.min-block-duration=2h — web.enable-lifecycle


#Optional command:


./thanos sidecar \
— tsdb.path “/home/nirav/Downloads/prometheus-2.15.1.linux-amd64/data/” \
— prometheus.url “http://localhost:9090" \
— objstore.config-file “bucket.yml”

./thanos compact \
— data-dir /tmp/thanos-compact \
— objstore.config-file=”bucket.yml” \
— http-address=”" \
— wait

Step3: Add thanos processes on Thanos server

Step3.1: Start Services on Thanos server

./thanos store \
— data-dir “/home/nirav/Downloads/tempthanos/” \
— objstore.config-file “bucket.yml”

./thanos query \
— http-address “” \
— query.replica-label “replica” \
— store “” \
— grpc-address=”"

Step3.2: Visualize thanos UI


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade