카테고리 없음
[Linux]Grafana Alloy 및 Prometheus & Loki 연동
cumo
2025. 6. 17. 04:01
Grafana Alloy | Grafana Alloy documentation
Migrate to Alloy Learn how to migrate to Alloy from Grafana Agent Operator, Prometheus, Promtail, Grafana Agent Static, or Grafana Agent Flow.
grafana.com
Grafana Alloy란?
Alloy는 Grafana에서 개발한 오픈소스 툴로 로그,메트릭,트레이스, 프로파일링 데이터를 수집하는 경량화 도구이며
클라우드, 온프레미스 환경에서 모두 사용 가능함
- 통합 텔레메트리 수집: Otel, Prometheus, Pyroscope, Loki 등 다양한 메트릭,로그,트레이스 및 프로파일링 도구에 대한 파이프라인 제공
- 호환성: OTel collector, Promethus 에이전트, Promtail 호환
- 리소스 효율: 프로메테우스 대비 1/10 수준 리소스 메트릭 수집
- Grafaana LGTM 스택 지원 : Loki(로그), Grafana(시각화), Tempo(트레이스), Mimir(매트릭) 연동
Grafana Alloy 설치
1. Kubernetes (Helm Chart) 설치 [공식문서]
#helm 설치
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
# helm repo 추가
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
# helm pull
helm pull grafana/alloy --untar # 압축해제 옵션
# helm install
cd alloy
helm install grafana-alloy .
Grafana Alloy 사용
설정파일 문법(Configuration Syntax)
컴포넌트 [공식문서]
- 추가적인 플러그인이나 모듈 설치 없이 설정파일 내 컴포넌트 정의 및 구성
- Grafana 문서를 통해 목록과 방법 제공
- 기존 ( Static mode, flow mode)와 별개로 HCL 기반의 River 언어로 통합
Alloy 구조 개념: 컴포넌트 기반 구성
구조
[컴포넌트 블록] ─┬─ 속성 (Attribute)
├─ 중첩 블록 (Block)
└─ 표현식 (Expression)
# Loki 로그 수집 컴포넌트 정의 (파일 기반)
loki.source.file "flask_logs" {
# 수집할 로그 파일 경로 (Flask 앱의 로그가 저장된 위치)
path = "/var/log/app.log"
# 로그에 포함할 라벨 정의 (Loki에서 필터링 조건으로 사용)
labels = {
job = "flask-ai" # 로그 검색 시 {job="flask-ai"} 로 필터링 가능
}
# 수집한 로그를 전송할 대상 컴포넌트 (loki.write.default)
forward_to = [loki.write.default.receiver]
}
# Loki로 로그를 전송하는 컴포넌트 정의
loki.write "default" {
endpoint {
# 로그를 전송할 Loki의 API 주소
url = "http://loki.monitoring.svc:3100/loki/api/v1/push"
# 이 주소는 Kubernetes 내의 Loki 서비스 ClusterIP 또는 DNS 주소여야 함
}
}
Config-Reloader 구성
# 형식
curl -X POST http://<ALLOY_SERVICE_ENDPOINT>/-/reload
# 예시
curl -X POST http://localhost:12345/-/reload # 로컬
curl -X POST http://localhost:30003/-/reload # 노드포트
# 결과
config reloaded
Grafana Alloy 를 활용한 메트릭 수집 및 Prometheus 연동
프로메테우스 설치
#레포 추가
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
#파라미터 파일 생성
:monitor-values.yaml
prometheus:
service:
type: NodePort
nodeport: 30001
prometheusSpec:
scrapeInterval: "15s"
evaluationInterval: "15s"
podMonitorSelectorNilUsesHelmValues: false
servicMonitorSelectorNilUsesHelmValues: false
retention: 5d
retentionSize: "10Gib"
grafana:
defaultDashboardsTimezone: Asia/Seoul
adminPassword: prom-operator
service:
type: NodePort
nodePort: 30002
defaultRules:
create: false
prometheus-windows-exporter:
prometheus:
monitor:
enabled: false
alertmanager:
enabled: false
EOT
#배포
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack --version 69.3.1 \ -f monitor-values.yaml --create-namespace --namespace monitoring
# 확인
kubectl get prometheus,servicemonitors -n monitoring
kubectl get crd | grep monitoring