Thanos — Use case

NIRAV SHAH
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

Requirments

Prometheus 2.2+ is mendatory for the setup to work.

Installation steps:

1. Download latest binary of prometheus & thanos

wget https://github.com/thanos-io/thanos/releases/download/v0.9.0/thanos-0.9.0.linux-amd64.tar.gz
wget https://github.com/prometheus/prometheus/releases/download/v2.15.1/prometheus-2.15.1.linux-amd64.tar.gz
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

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

external_labels:
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
config:
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”: “thanostest@premium-poc.iam.gserviceaccount.com”,
“client_id”: “111579088233215168392”,
“auth_uri”: “https://accounts.google.com/o/oauth2/auth",
“token_uri”: “https://oauth2.googleapis.com/token",
“auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs",
“client_x509_cert_url”: “https://www.googleapis.com/robot/v1/metadata/x509/thanostest%40my-project.iam.gserviceaccount.com"
}

Step2.4: Start Services on prometheus server

#0.0.0.0:9090
./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=http://prometheus.example.com — web.route-prefix=/ — config.file /opt/prometheusum/prometheus.yml — log.level=info — storage.tsdb.retention=15d — storage.tsdb.path /opt/prometheus.data — storage.tsdb.max-block-duration=2h — storage.tsdb.min-block-duration=2h — web.enable-lifecycle

========================================

#Optional command:

GOOGLE_APPLICATION_CREDENTIALS=”my-project-ace639bd4d70.json”

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

#0.0.0.0:10902
./thanos compact \
— data-dir /tmp/thanos-compact \
— objstore.config-file=”bucket.yml” \
— http-address=”127.0.0.1:11901" \
— wait

Step3: Add thanos processes on Thanos server

Step3.1: Start Services on Thanos server

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

./thanos query \
— http-address “0.0.0.0:9090” \
— query.replica-label “replica” \
— store “127.0.0.1:10901” \
— grpc-address=”0.0.0.0:12901"

Step3.2: Visualize thanos UI

Reference:
https://banzaicloud.com/blog/hands-on-thanos/
https://github.com/improbable-eng/thanos/releases
https://improbable.io/blog/thanos-prometheus-at-scale
https://github.com/improbable-eng/thanos/blob/master/docs/getting-started.md

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