[monitoring] Thanos
Updated:
개요
- Website
- GitHub
- 장기 저장 기능이 있는 고가용성 오픈 소스 Prometheus 설정
- Apache-2.0 license
- CNCF Incubating Project
- 단일 바이너리의 핵심 기능으로 글로벌 쿼리 보기, 고가용성, 과거의 저렴한 데이터 액세스를 통한 데이터 백업을 제공
- 이러한 기능은 서로 독립적으로 배포 가능
- 즉각적인 이점 또는 테스트를 위해 준비된 Thanos 기능의 하위 집합을 가질 수 있으며 더 복잡한 환경에서 점진적으로 출시할 수 있도록 유연하게 만들 수 있음
- Golang으로 구축되었으므로 다양한 x64 운영 체제에서 실행 가능
- Thanos는 Kubernetes와 관련이 없음
- Kubernetes, Thanos 및 Prometheus는 CNCF의 일부이므로 Kubernetes 위에 있으므로 Kubernetes에 설치하는 몇 가지 다른 방법을 유지
- 구성 요소
- Sidecar
- Prometheus에 연결하고 쿼리를 위해 데이터를 읽거나 클라우드 스토리지에 업로드
- Thanos는 Prometheus 서버와 동일한 시스템 또는 동일한 포드에서 실행되는 Sidecar 프로세스를 통해 기존 Prometheus 서버와 통합
- 목적은 Prometheus 데이터를 Object Storage 버킷에 백업하고 다른 Thanos 구성 요소가 gRPC API를 통해 Prometheus 메트릭에 액세스할 수 있도록 하는 것
- reload Prometheus endpoint를 사용
--web.enable-lifecycle
플래그로 활성화 되어 있어야 함
- Store Gateway
- 클라우드 스토리지 버킷 내에서 메트릭을 제공
- Sidecar가 데이터를 선택한 개체 스토리지에 백업하면 Prometheus 보존을 줄이고 로컬에 덜 저장하는 것이 가능
- 그러나 모든 과거 데이터를 다시 쿼리할 방법이 필요
- Store Gateway는 Sidecar와 동일한 gRPC 데이터 API를 구현하지만 객체 스토리지 버킷에서 찾을 수 있는 데이터로 백업함으로써 이를 수행
- 오브젝트 스토리지의 데이터에 대한 기본 정보를 캐싱하기 위해 소량의 디스크 공간을 차지
- 몇 기가바이트를 초과하지 않으며 다시 시작 시간을 개선하는 데 사용
- 유용하지만 다시 시작할 때 이를 보존할 필요는 없음
- Sidecar 및 쿼리 노드와 마찬가지로 Store Gateway는 StoreAPI를 노출하며 Thanos Querier에서 검색
thanos store \ --data-dir /var/thanos/store \ # Disk space for local caches --objstore.config-file bucket_config.yaml \ # Bucket to fetch data from --http-address 0.0.0.0:19191 \ # HTTP endpoint for collecting metrics on the Store Gateway --grpc-address 0.0.0.0:19090 # GRPC endpoint for StoreAPI
- Compactor
- 클라우드 스토리지 버킷에 저장된 데이터에 대해 압축, 다운샘플링 및 보존을 적용
- 로컬 Prometheus 설치는 쿼리 효율성을 개선하기 위해 이전 데이터를 주기적으로 압축
- Sidecar는 데이터를 최대한 빨리 백업하기 때문에 오브젝트 스토리지의 데이터에 동일한 프로세스를 적용할 방법이 필요
- compactor는 단순히 개체 저장소를 검색하고 필요한 경우 압축을 처리함과 동시에 쿼리 속도를 높이기 위해 다운샘플링된 데이터 복사본을 만드는 역할
thanos compact \ --data-dir /var/thanos/compact \ # Temporary workspace for data processing --objstore.config-file bucket_config.yaml \ # Bucket where to apply the compacting --http-address 0.0.0.0:19191 # HTTP endpoint for collecting metrics on the Compactor
- compactor는 쿼리 또는 데이터 백업의 중요한 경로에 있지 않음
- 정기적인 배치 작업으로 실행하거나 항상 가능한 한 빨리 데이터를 압축하기 위해 실행 상태로 둘 수 있음
- 데이터 처리를 위해 100-300GB의 로컬 디스크 공간을 제공하는 것울 권장
- 싱글톤으로 실행해야 하며 버킷의 데이터를 수동으로 수정할 때 실행하면 안됨
- Receiver
- Prometheus의 remote-write WAL에서 데이터를 수신하고 이를 노출 및/또는 클라우드 스토리지에 업로드
- Ruler/Rule
- 표시 및/또는 업로드를 위해 Thanos의 데이터에 대한 기록 및 경고 규칙을 평가
- Querier/Query
- Prometheus의 v1 API를 구현하여 기본 구성 요소의 데이터를 집계
- 이제 하나 이상의 Prometheus 인스턴스에 대해 Sidecar를 설정했으므로 Thanos의 전역 쿼리 계층을 사용하여 모든 인스턴스에 대해 PromQL 쿼리를 한 번에 평가 가능
- 쿼리 구성 요소는 상태 비저장 및 수평 확장이 가능하며 원하는 수의 복제본과 함께 배포 가능
- Sidecars에 연결되면 지정된 PromQL 쿼리에 대해 연결해야 하는 Prometheus 서버를 자동으로 감지
- Prometheus의 공식 HTTP API를 구현하므로 Grafana와 같은 외부 도구와 함께 사용 가능
- ad-hoc querying and stores status를 위한 Prometheus UI의 derivative를 제공
- Sidecar에 연결하고 HTTP UI를 노출하도록 Thanos Querier를 설정
thanos query \ --http-address 0.0.0.0:19192 \ # HTTP Endpoint for Thanos Querier UI --store 1.2.3.4:19090 \ # Static gRPC Store API Address for the query node to query --store 1.2.3.5:19090 \ # Also repeatable --store dnssrv+_grpc._tcp.thanos-store.monitoring.svc # Supports DNS A & SRV records
- Deduplicating Data from Prometheus HA pairs
- 쿼리 구성 요소는 Prometheus HA 쌍에서 수집된 데이터의 중복을 제거 가능
- 이를 위해서는 주어진 Prometheus 인스턴스의 역할을 식별하기 위해 Prometheus의 global.external_labels 구성 블록을 구성해야 함
- 일반적인 선택은 단순히 레이블 이름은 “replica”, 값은 원하는 대로 두는 것
- Kubernetes stateful deployment에서 replica 레이블은 pod 이름인 경우도 있음
- Prometheus configuration file
global: external_labels: region: eu-west monitor: infrastructure replica: A # ...
- Prometheus 인스턴스 Reload 후 Thanos Querier에서 replica를 중복 제거를 수행할 레이블로 정의
thanos query \ --http-address 0.0.0.0:19192 \ --store 1.2.3.4:19090 \ --store 1.2.3.5:19090 \ --query.replica-label replica # Replica label for de-duplication --query.replica-label replicaX # Supports multiple replica labels for de-duplication
- Query Frontend
- Prometheus의 v1 API는 응답을 캐싱하는 동안 쿼리에 프록시하고 쿼리 날짜별로 선택적 분할을 구현
- Communication Between Components
- 노드 간에 필요한 유일한 통신은 Thanos Querier가 사용자가 제공하는 gRPC storeAPI에 도달할 수 있도록 하는 것
- Thanos Querier는 주기적으로 Info 엔드포인트를 호출하여 최신 메타데이터를 수집하고 지정된 StoreAPI의 상태를 확인
- 메타데이터에는 각 노드의 시간 창 및 외부 레이블에 대한 정보가 포함
- 쿼리 구성 요소에 데이터를 쿼리해야 하는 StoreAPI에 대해 알리는 다양한 방법 존재
- 가장 간단한 방법은 잘 알려진 주소의 정적 목록을 사용하여 쿼리
- 반복 가능하므로 필요한 만큼 엔드포인트 추가 가능
- dns+ 또는 dnssrv+가 접두사로 붙은 DNS 도메인을 추가하여 Thanos Querier가 A 또는 SRV 조회를 수행하여 통신에 필요한 모든 IP를 가져오도록 하는 것도 가능
thanos query \ --http-address 0.0.0.0:19192 \ # Endpoint for Thanos Querier UI --grpc-address 0.0.0.0:19092 \ # gRPC endpoint for Store API --store 1.2.3.4:19090 \ # Static gRPC Store API Address for the query node to query --store 1.2.3.5:19090 \ # Also repeatable --store dns+rest.thanos.peers:19092 # Use DNS lookup for getting all registered IPs as separate StoreAPIs
- Deployment with Sidecar
- Deployment with Receive
- Sidecar
- External storage
- Prometheus의 데이터를 구성된 개체 저장소에 쓰도록 Sidecar 구성 가능
thanos sidecar \ --tsdb.path /var/prometheus \ # TSDB data directory of Prometheus --prometheus.url "http://localhost:9090" \ # Be sure that the sidecar can use this url! --objstore.config-file bucket_config.yaml \ # Storage configuration for uploading data
- YAML 파일 형식은 선택한 공급자에 따라 다름
- 지원하는 스토리지 유형
- 데이터 백업에 관심이 없다면
--objstore.config-file
플래그를 생략
- Prometheus의 데이터를 구성된 개체 저장소에 쓰도록 Sidecar 구성 가능
- Store API
- Sidecar 구성 요소는 gRPC Store API를 구현하고 노출
- Sidecar 구현을 통해 Prometheus에 저장된 메트릭 데이터 쿼리 가능
thanos sidecar \ --tsdb.path /var/prometheus \ --objstore.config-file bucket_config.yaml \ # Bucket config file to send data to --prometheus.url http://localhost:9090 \ # Location of the Prometheus HTTP server --http-address 0.0.0.0:19191 \ # HTTP endpoint for collecting metrics on the Sidecar --grpc-address 0.0.0.0:19090 # GRPC endpoint for StoreAPI
- Uploading old metrics
- Sidecar가
--shipper.upload-compacted
플래그와 함께 실행되면 시작 시 Prometheus 로컬 스토리지의 모든 기존 블록을 동기화- 이 버킷에 대해 블록 업로드로 Sidecar를 실행하지 않는다고 가정
- 그렇지 않으면 버킷에서 겹치는 블록을 제거하기 위해 수동 단계가 필요
- Sidecar가
- External Labels
- Prometheus는 주어진 Prometheus 인스턴스의 “external labels” 구성을 허용
- 이는 해당 인스턴스의 역할을 전역적으로 식별하기 위한 것
- Thanos는 모든 인스턴스에서 데이터를 집계하는 것을 목표로 하므로 일관된 외부 레이블 세트를 제공하는 것이 중요
- 모든 Prometheus 인스턴스에는 전역적으로 고유한 식별 레이블 집합이 있어야 함
- Prometheus configuration file
global: external_labels: region: eu-west monitor: infrastructure replica: A
설계
- Thanos는 장기 저장 기능이 있는 고가용성 Prometheus 설정으로 구성할 수 있는 구성 요소 집합
- 주요 목표는 작동 단순성과 Prometheus의 안정성 속성을 유지하는 것
- 아키텍쳐
- Thanos는 고유하고 분리된 목적을 가진 클러스터된 구성 요소 시스템
- Metric sources, Stores, Queriers
- Thanos는 고유하고 분리된 목적을 가진 클러스터된 구성 요소 시스템
- Scaling
- 구성 요소 중 어떤 것도 샤딩 수단을 제공하지 않음
- 명시적으로 확장 가능한 유일한 구성 요소는 상태 비저장이고 임의로 확장할 수 있는 쿼리 노드
- 외부 개체 스토리지 시스템에 의존하여 스토리지 용량 확장이 보장
- 저장소, 규칙 및 압축 프로그램 노드는 모두 단일 인스턴스 또는 고가용성 쌍 내에서 크게 확장될 것으로 예상
- Cost
실습
- east 장비
- Prometheus 설치
- kube-prometheus-stack-values.yaml
prometheus: prometheusSpec: externalLabels: region: east service: type: NodePort
- install-prometheus.sh
#!/bin/bash kubectl create namespace prometheus-stack helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack -f ./kube-prometheus-stack-values.yaml -n prometheus-stack
- kube-prometheus-stack-values.yaml
- Thanos 바이너리 다운로드
- Thanos Sidecar 실행
- 장비 아이피가 1.1.1.1이라 가정
./thanos sidecar --prometheus.url "http://1.1.1.1:30090" --grpc-address 0.0.0.0:19090
- Prometheus 설치
- west 장비
- Prometheus 설치
- kube-prometheus-stack-values.yaml
prometheus: prometheusSpec: externalLabels: region: west service: type: NodePort
- install-prometheus.sh
#!/bin/bash kubectl create namespace prometheus-stack helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack -f ./kube-prometheus-stack-values.yaml -n prometheus-stack
- kube-prometheus-stack-values.yaml
- Thanos 바이너리 다운로드
- Thanos Sidecar 실행
- 장비 아이피가 2.2.2.2이라 가정
./thanos sidecar --prometheus.url "http://2.2.2.2:30090" --grpc-address 0.0.0.0:19090
- Prometheus 설치
- Thanos query 실행
- 장비 아이피가 3.3.3.3이라 가정
- east 장비나 west 장비에서 수행해도 무방
./thanos query --http-address 0.0.0.0:19192 --store 1.1.1.1:19090 --store 2.2.2.2:19090
- Thanos query UI 접속 후 메트릭 확인(http://3.3.3.3:19192/)