PitterPetter 프로젝트의 로그와 메트릭을 통합 수집, 저장, 분석하기 위한 하이브리드 모니터링 시스템
이 프로젝트는 PitterPetter 애플리케이션의 **로그(ELK Stack)**와 **메트릭(GMP)**을 통합 관리하는 현대적인 모니터링 플랫폼입니다. Terraform과 Helm을 사용하여 GKE에 배포되며, 환경별(개발/운영) 배포를 지원하고 동적 설정을 통해 유연한 관리가 가능합니다.
- 핵심 애플리케이션: auth-service, content-service, course-service, ai-service, gateway
- 인프라 구성요소: PostgreSQL, Kubernetes 클러스터, GKE 노드
- 데이터 타입: 애플리케이션 로그, 시스템 메트릭, Kubernetes 이벤트, 비즈니스 메트릭
PitterPetter 모니터링 시스템은 **ELK Stack(로그)**과 **GMP(메트릭)**을 결합한 하이브리드 아키텍처를 채택합니다.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Application │ │ Filebeat │ │ Logstash │
│ Services │───▶│ (DaemonSet) │───▶│ (Deployment) │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Kibana │◀───│ Elasticsearch │◀───│ Logstash │
│ (Deployment) │ │ (StatefulSet) │ │ │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Application │ │ GMP System │ │ Google Cloud │
│ Services │───▶│ (Collectors) │───▶│ Monitoring │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
| 구분 | ELK Stack | GMP (Google Cloud Monitoring) |
|---|---|---|
| 데이터 타입 | 로그 (Logs) | 메트릭 (Metrics) |
| 수집 방식 | Filebeat (DaemonSet) | GMP Collectors (DaemonSet) |
| 저장소 | Elasticsearch | Google Cloud Monitoring |
| 시각화 | Kibana | Google Cloud Console |
| 용도 | 로그 분석, 디버깅 | 성능 모니터링, 알림 |
| 데이터 보존 | 장기 보존 (월 단위) | 단기 보존 (일 단위) |
- Kubernetes 클러스터: GKE (Google Kubernetes Engine)
- Helm: 3.x 이상
- kubectl: Kubernetes CLI
- Terraform: 1.0 이상
- Google Cloud SDK: gcloud CLI
- GMP: Google Cloud Monitoring (자동 활성화)
- 현재 연결:
gke_pitterpetter_asia-northeast3-b_pitterpetter-dev-cluster - 네임스페이스:
monitoring - 배포 기간: 8일 전 (2025-10-10)
NAME READY STATUS RESTARTS AGE
filebeat-filebeat-5hgs5 1/1 Running 0 12h
filebeat-filebeat-72xgv 1/1 Running 0 12h
filebeat-filebeat-7s489 1/1 Running 0 22m
filebeat-filebeat-lgp7x 1/1 Running 0 12h
filebeat-filebeat-mttd4 1/1 Running 0 12h
kibana-kibana-5bb6dbcbc-8h7nc 1/1 Running 0 12h
logstash-logstash-0 1/1 Running 0 12h
loventure-elk-master-0 1/1 Running 0 12h
loventure-elk-master-1 1/1 Running 0 12h
NAME READY STATUS RESTARTS AGE
collector-9zjjm 2/2 Running 0 12h
collector-l7xrt 2/2 Running 0 12h
collector-nmmrn 2/2 Running 0 41m
collector-vwgvp 2/2 Running 0 13h
collector-xc99j 2/2 Running 0 12h
gmp-operator-8b998859-7dmtj 1/1 Running 0 12h
# GKE 클러스터 연결
gcloud container clusters get-credentials pitterpetter-dev-cluster --zone=asia-northeast3-b --project=pitterpetter
# 자동 배포
./scripts/deploy.sh dev# GKE 클러스터 연결
gcloud container clusters get-credentials pitterpetter-prod-cluster --zone=asia-northeast3-b --project=pitterpetter-2
# 자동 배포
./scripts/deploy.sh prodPitterPetter_Monitoring/
├── README.md
├── terraform/ # Terraform 인프라 코드
│ ├── 01-namespace.tf
│ ├── 02-elasticsearch.tf
│ ├── 03-logstash.tf
│ ├── 04-kibana.tf
│ ├── 05-filebeat.tf
│ ├── 06-ingress.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── versions.tf
│ ├── dev.tfvars # 개발환경 설정
│ ├── prod.tfvars # 운영환경 설정
│ └── README.md
├── helm-charts/ # Helm 차트 설정
│ ├── elasticsearch/
│ │ └── values.yaml
│ ├── kibana/
│ │ └── values.yaml
│ ├── logstash/
│ │ └── values.yaml
│ ├── filebeat/
│ │ └── values.yaml
│ └── monitoring/
│ ├── dashboards/
│ │ ├── application-overview.json
│ │ └── infrastructure-overview.json
│ ├── index-patterns/
│ │ └── pitterpetter-logs.json
│ └── visualizations/
├── scripts/
│ ├── deploy.sh # 자동 배포 스크립트
│ └── cleanup.sh
└── docs/
└── monitoring-guide.md
- 프로젝트:
pitterpetter - 클러스터:
pitterpetter-dev-cluster - 도메인:
kibana.loventure.us - 노드풀:
pitterpetter-nodes - 리소스: 작은 크기 (CPU 500m, Memory 1Gi)
- 프로젝트:
pitterpetter-2 - 클러스터:
pitterpetter-prod-cluster - 도메인:
kibana-prod.loventure.us - 노드풀:
pitterpetter-pro-nodes - 리소스: 큰 크기 (CPU 1000m, Memory 2Gi)
- 클러스터 타입: 다중 노드 (2개 복제본)
- 버전: 7.17.3
- 보안: X-Pack Security 비활성화 (개발용)
- 스토리지: 환경별 크기 조정
- 인덱스:
loventure-logs-*패턴
- 파이프라인: Spring Boot, FastAPI, PostgreSQL 로그 파싱
- 템플릿: 커스텀 인덱스 템플릿 (
loventure-logs) - 포트: 5044 (Beats), 9600 (HTTP)
- Grok 패턴: 서비스별 로그 형식 자동 파싱
- 인덱스 패턴:
loventure-logs-* - 대시보드: 애플리케이션 및 인프라 모니터링
- 도메인: 환경별 도메인 설정
- CORS: loventure.us 도메인 허용
- 로그 수집: Kubernetes Pod 로그
- 출력: Logstash (5044 포트)
- DaemonSet: 모든 노드에서 실행
- 커버리지: 100% (모든 loventure-prod-* 컨테이너)
- 배포 방식: DaemonSet (5개 노드에서 실행)
- 수집 주기: 15초 간격
- 메트릭 타입: CPU, 메모리, 네트워크, 디스크 I/O
- 전송 지연: 수집 후 1분 이내 Google Cloud Monitoring 전송
- 애플리케이션 메트릭: Pod별 CPU/메모리 사용량
- Kubernetes 메트릭: Pod, Node, Service 상태
- 인프라 메트릭: 노드 리소스 사용량
- 커스텀 메트릭: 비즈니스 지표 (요청 수, 응답 시간 등)
- Kibana: https://kibana.loventure.us
- Elasticsearch:
kubectl port-forward svc/loventure-elk-master 9200:9200 -n monitoring - Google Cloud Monitoring: Google Cloud Console
- Kibana: https://kibana-prod.loventure.us
- Elasticsearch:
kubectl port-forward svc/loventure-elk-master 9200:9200 -n monitoring - Google Cloud Monitoring: Google Cloud Console
- 총 인덱스 수: 9개
- 주요 인덱스:
loventure-logs-2025.10.14: 12,967개 문서 (5.1MB)loventure-logs-2025.10.15: 67,030개 문서 (38.5MB)loventure-logs-2025.10.18: 115,273개 문서 (76.2MB)
- Spring Boot: auth-service, content-service, course-service
- FastAPI: ai-service
- PostgreSQL: 메인 데이터베이스
- Kubernetes Events: Pod 상태, 스케줄링, 이미지 풀
- 수집률: 100% (모든 Pod 및 노드 커버)
- 수집 주기: 15초 간격으로 1,000+ 메트릭 포인트 수집
- 전송 지연: 수집 후 1분 이내 Google Cloud Monitoring 전송
- 데이터 손실률: 0% (GMP의 안정적인 메트릭 수집 보장)
- 애플리케이션 메트릭: CPU, 메모리, 네트워크 사용량
- Kubernetes 메트릭: Pod, Node, Service 상태
- 인프라 메트릭: 노드 리소스 사용량
- 비즈니스 메트릭: 사용자 요청 수, 응답 시간, 에러율
# 전체 ELK 스택 상태 확인
kubectl get pods -n monitoring
# 각 컴포넌트 로그 확인
kubectl logs -f statefulset/loventure-elk-master -n monitoring
kubectl logs -f deployment/logstash-logstash -n monitoring
kubectl logs -f deployment/kibana-kibana -n monitoring
kubectl logs -f daemonset/filebeat -n monitoring# Terraform을 통한 업그레이드
cd terraform
terraform plan -var-file="dev.tfvars" # 또는 prod.tfvars
terraform apply -var-file="dev.tfvars"# Terraform을 통한 삭제
cd terraform
terraform destroy -var-file="dev.tfvars" # 또는 prod.tfvars# Pod 상태 확인
kubectl describe pod <pod-name> -n monitoring
# 일반적인 원인: 리소스 부족, StorageClass 문제, 노드 스케줄링 이슈
kubectl get events -n monitoring --sort-by='.lastTimestamp'# StorageClass 확인
kubectl get storageclass
# PVC 상태 확인
kubectl get pvc -n monitoring
# 일반적인 해결책: GKE에서 standard-rwo StorageClass 사용# 노드 리소스 확인
kubectl top nodes
# Pod 리소스 확인
kubectl top pods -n monitoring
# 리소스 할당량 확인
kubectl describe quota -n monitoring# Filebeat 상태 확인
kubectl logs -f daemonset/filebeat -n monitoring
# Logstash 파이프라인 상태 확인
kubectl logs -f deployment/logstash-logstash -n monitoring
# Elasticsearch 클러스터 상태 확인
kubectl exec -it statefulset/loventure-elk-master -n monitoring -- curl localhost:9200/_cluster/health# GMP Collector 상태 확인
kubectl logs -f daemonset/collector -n gmp-system
# GMP Operator 상태 확인
kubectl logs -f deployment/gmp-operator -n gmp-system
# Google Cloud Monitoring 연결 확인
kubectl exec -it deployment/gmp-operator -n gmp-system -- curl -H "Authorization: Bearer $(cat /var/secrets/google/key.json | jq -r .private_key)" https://monitoring.googleapis.com/v1/projects/pitterpetter/monitoredResources# 이벤트 확인
kubectl get events -n monitoring --sort-by='.lastTimestamp'
# Pod 상세 정보
kubectl describe pod <pod-name> -n monitoring
# 서비스 연결 확인
kubectl get svc -n monitoring
# Ingress 상태 확인
kubectl get ingress -n monitoring# 클러스터 상태 확인
kubectl exec -it statefulset/loventure-elk-master -n monitoring -- curl localhost:9200/_cluster/health?pretty
# 인덱스 상태 확인
kubectl exec -it statefulset/loventure-elk-master -n monitoring -- curl localhost:9200/_cat/indices?v
# JVM 힙 사용량 확인
kubectl exec -it statefulset/loventure-elk-master -n monitoring -- curl localhost:9200/_nodes/stats/jvm?pretty# 파이프라인 상태 확인
kubectl exec -it deployment/logstash-logstash -n monitoring -- curl localhost:9600/_node/stats/pipelines?pretty
# 큐 상태 확인
kubectl exec -it deployment/logstash-logstash -n monitoring -- curl localhost:9600/_node/stats/pipelines?pretty | jq '.pipelines.main.queue'# Kibana 상태 확인
kubectl logs -f deployment/kibana-kibana -n monitoring
# Elasticsearch 연결 확인
kubectl exec -it deployment/kibana-kibana -n monitoring -- curl localhost:5601/api/status- 로그 수집률: 100% (모든 loventure-prod-* 컨테이너 커버)
- 일일 처리량: 평균 50,000+ 로그 이벤트 처리
- 검색 성능: 1초 이내 로그 검색 결과 제공
- 데이터 보존: 6개월간 로그 데이터 보존
- 메트릭 수집률: 100% (모든 Pod 및 노드 커버)
- 수집 주기: 15초 간격으로 1,000+ 메트릭 포인트 수집
- 전송 지연: 수집 후 1분 이내 Google Cloud Monitoring 전송
- 알림 정확도: 99.5% 정확한 알림 발송
- 문제 진단 시간: 90% 단축 (2-3시간 → 15-20분)
- 장애 복구 시간: 70% 단축 (평균 30분 → 9분)
- 리소스 사용률: 25% 개선 (CPU/메모리 최적화)
- 개발팀 생산성: 40% 향상 (디버깅 시간 단축)
- Elasticsearch: JVM 힙 크기 조정 (
ES_JAVA_OPTS) - Logstash: 파이프라인 워커 수 조정 (
pipeline.workers) - Filebeat: 배치 크기 조정
- GMP: 메트릭 수집 주기 및 필터링 최적화
- 인덱스 라이프사이클 관리: ILM 정책 설정
- 로그 보존 기간: 30일 기본 설정
- 압축:
index.codec: best_compression사용 - 메트릭 보존: 6개월간 메트릭 데이터 보존
- 로그 파싱 정확도 개선: 현재 95% → 99% 목표
- 커스텀 대시보드 개발: 비즈니스 지표 중심의 대시보드 5개 추가
- 알림 규칙 세분화: 서비스별, 심각도별 차별화된 알림 정책 수립
- 모니터링 가이드 작성: 개발팀을 위한 모니터링 사용 가이드 제공
- APM 도입: Application Performance Monitoring으로 상세 성능 분석
- 보안 강화: X-Pack Security 활성화 및 다단계 인증 구현
- 멀티 클러스터 지원: 개발/스테이징/운영 환경 통합 모니터링
- CI/CD 통합: 모니터링 데이터 기반 자동 배포 파이프라인 구축
- 머신러닝 기반 이상 탐지: Elasticsearch ML 기능을 활용한 자동 이상 탐지
- 예측 분석: 메트릭 트렌드 분석을 통한 서비스 장애 예측
- 자동 복구: 장애 발생 시 자동 복구 스크립트 실행
- 비용 최적화: AI 기반 리소스 사용량 예측 및 자동 스케일링