Created
January 17, 2023 12:38
-
-
Save Kartik-Garg/b4fbdfe37023f5db5dda6b9318a310af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Starts three Prometheus servers scraping themselves and sidecars for each. | |
| # Two query nodes are started and all are clustered together. | |
| trap 'kill 0' SIGTERM | |
| MINIO_ENABLED=${MINIO_ENABLED:-""} | |
| MINIO_EXECUTABLE=${MINIO_EXECUTABLE:-"minio"} | |
| MC_EXECUTABLE=${MC_EXECUTABLE:-"mc"} | |
| PROMETHEUS_EXECUTABLE=${PROMETHEUS_EXECUTABLE:-"/home/kartik/Documents/prometheus-2.41.0.linux-amd64/prometheus"} | |
| THANOS_EXECUTABLE=${THANOS_EXECUTABLE:-"/home/kartik/go/bin/thanos"} | |
| S3_ENDPOINT="" | |
| export MINIO_ACCESS_KEY="THANOS" | |
| export MINIO_SECRET_KEY="ITSTHANOSTIME" | |
| export MINIO_ENDPOINT="127.0.0.1:9000" | |
| export MINIO_BUCKET="thanos" | |
| export S3_ACCESS_KEY=${MINIO_ACCESS_KEY} | |
| export S3_SECRET_KEY=${MINIO_SECRET_KEY} | |
| export S3_BUCKET=${MINIO_BUCKET} | |
| export S3_ENDPOINT=${MINIO_ENDPOINT} | |
| export S3_INSECURE="true" | |
| export S3_V2_SIGNATURE="true" | |
| mkdir -p data/minio | |
| ${MINIO_EXECUTABLE} server ./data/minio \ | |
| --address ${MINIO_ENDPOINT} & | |
| # sleep 3 | |
| # create the bucket | |
| ${MC_EXECUTABLE} config host add tmp http://${MINIO_ENDPOINT} ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY} | |
| ${MC_EXECUTABLE} mb tmp/${MINIO_BUCKET} | |
| ${MC_EXECUTABLE} config host rm tmp | |
| # bucket config | |
| cat <<EOF >data/bucket.yml | |
| type: S3 | |
| config: | |
| bucket: $S3_BUCKET | |
| endpoint: $S3_ENDPOINT | |
| insecure: $S3_INSECURE | |
| signature_version2: $S3_V2_SIGNATURE | |
| access_key: $S3_ACCESS_KEY | |
| secret_key: $S3_SECRET_KEY | |
| EOF | |
| # Rules | |
| cat >data/rules.yml <<-EOF | |
| groups: | |
| - name: example | |
| rules: | |
| - record: job:go_threads:sum | |
| expr: sum(go_threads) by (job) | |
| EOF | |
| rm -rf data/prom0 | |
| mkdir -p data/prom0/ | |
| cat >data/prom0/prometheus.yml <<-EOF | |
| global: | |
| external_labels: | |
| prometheus: prom-0 | |
| rule_files: | |
| - 'rules.yml' | |
| scrape_configs: | |
| - job_name: prometheus | |
| scrape_interval: 5s | |
| static_configs: | |
| - targets: | |
| - "localhost:9090" | |
| - "localhost:59090" | |
| - "localhost:59090" | |
| - "localhost:59090" | |
| - job_name: thanos-sidecar | |
| scrape_interval: 5s | |
| static_configs: | |
| - targets: | |
| - "localhost:10902" | |
| - job_name: thanos-store | |
| scrape_interval: 5s | |
| static_configs: | |
| - targets: | |
| - "localhost:10906" | |
| - job_name: thanos-receive | |
| scrape_interval: 5s | |
| static_configs: | |
| - targets: | |
| - "localhost:10909" | |
| - "localhost:11909" | |
| - "localhost:12909" | |
| - job_name: thanos-query | |
| scrape_interval: 5s | |
| static_configs: | |
| - targets: | |
| - "localhost:10904" | |
| - "localhost:10914" | |
| EOF | |
| cp data/rules.yml data/prom0/rules.yml | |
| ${PROMETHEUS_EXECUTABLE} \ | |
| --config.file data/prom0/prometheus.yml \ | |
| --storage.tsdb.path data/prom0 \ | |
| --log.level warn \ | |
| --web.enable-lifecycle \ | |
| --storage.tsdb.min-block-duration=2h \ | |
| --storage.tsdb.max-block-duration=2h \ | |
| --web.listen-address 0.0.0.0:9090 & | |
| OBJSTORECFG="" | |
| if [ -n "${MINIO_ENABLED}" ]; then | |
| OBJSTORECFG="--objstore.config-file data/bucket.yml" | |
| fi | |
| ${THANOS_EXECUTABLE} store \ | |
| --debug.name store-name \ | |
| --log.level debug \ | |
| --grpc-address 0.0.0.0:10905 \ | |
| --grpc-grace-period 1s \ | |
| --http-address 0.0.0.0:10906 \ | |
| --http-grace-period 1s \ | |
| --data-dir data/store \ | |
| --objstore.config-file "data/bucket.yml" \ | |
| ${OBJSTORECFG} & | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment