728x90
반응형
SMALL
학습내용
- Distributed Tracing (분산 추적)
- Log Aggregation (로그 중앙화)
- Metrics 수집 (Prometheus + Grafana)
학습정리
1. Distributed Tracing (분산 추적)
여러 서비스 간 호출 흐름을 추적하여 성능 문제 해결
Jaeger, Zipkin, OpenTelemetry 활용
Zipkin 적용 실습
- 서비스 간 호출 흐름을 Trace ID를 자동 전파하여 요청 흐름을 시각적으로 확인
- Docker 에서 사용
docker run -d -p 9411:9411 openzipkin/zipkin
SpringBoot 에서 사용
의존성 추가
dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-sleuth' implementation 'org.springframework.cloud:spring-cloud-sleuth-zipkin' }
application.yml 설정
spring: # Spring Boot 서비스 간 트레이싱 자동 적용 sleuth: sampler: probability: 1.0. # 1.0 = 100% 요청 추적 integration: enabled: true scheduled: enabled: true messaging: kafka: enabled: true #Zipkin과 연동하여 추적 결과를 UI에서 확인 zipkin: base-url: http://zipkin:9411 enabled: true sender: type: web
2. Log Aggregation (로그 중앙화)
- 여러 서비스의 로그를 하나의 시스템에서 관리
- ELK 스택 (Elasticsearch + Logstash + Kibana) 활용
3. Metrics 수집 (Prometheus + Grafana)
서비스 성능 (CPU, 메모리, 요청수 등) 실시간 모니터링
Prometheus
시계열(time-series) 데이터 수집 및 저장을 위한 모니터링 시스템
Spring Boot Actuator + Micrometer와 연동하여 애플리케이션 성능 지표 수집
exporter를 활용하여 다양 매트릭스를 적재가 가능
Docker 에서 실행
docker run -d --name=prometheus -p 9090:9090 -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
Prometheus 설정 (prometheus.yml)
global: scrape_interval: 15s # 기본적으로 15초마다 모든 타겟의 메트릭을 수집 evaluation_interval: 15s # 15초마다 규칙(rule) 평가 수행 scrape_configs: - job_name: 'prometheus' # Prometheus 자체 모니터링 static_configs: - targets: ['localhost:9090'] # Prometheus 서버 자체를 모니터링 - job_name: 'spring-boot' # Spring Boot 애플리케이션 모니터링 metrics_path: '/actuator/prometheus' # 메트릭을 가져올 엔드포인트 지정 scrape_interval: 5s # 이 특정 job만 5초마다 메트릭 수집 static_configs: - targets: ['order-api:8083'] # Spring Boot 애플리케이션이 실행되는 서버
Spring Boot에서 Prometheus 연동
의존성 추가
dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-registry-prometheus' }
application.yml
management: endpoints: web: exposure: include: prometheus,health,info,metrics # Actuator 엔드포인트 활성화 endpoint: health: show-details: always # 건강 상태 상세 정보 표시 metrics: enabled: true # 메트릭 엔드포인트 활성화 prometheus: enabled: true # Prometheus 메트릭 엔드포인트 활성화 metrics: export: prometheus: enabled: true # Prometheus로 메트릭 내보내기 활성화 tags: application: ${spring.application.name:order-api} # 기본 태그 설정
- 매트릭 확인 방법
- 브라우저에서 http://localhost:9090 접속
- "Status" → "Targets" 메뉴에서 spring-boot-app이 정상적으로 연결되었는지 확인
- “Graph" 탭에서 http_server_requests_seconds_count 같은 메트릭 검색 가능
Grafana
- Prometheus 데이터를 시각적으로 표현하는 대시보드 도구
- CPU 사용량, 메모리, 요청 수, 응답 시간 등을 그래프로 시각화
- Docker 에서 실행
docker run -d --name=grafana -p 3000:3000 grafana/grafana
- 데이터 소스 추가
- http://localhost:3000 접속
- 로그인 (admin / admin)
- Configuration > Data Sources 클릭
- Add data source 버튼 클릭
- Prometheus 선택
- URL: http://localhost:9090 입력 후 저장
- 대시보드 추가
- Create > Dashboard 클릭
- Add a new panel 클릭
- Metric 입력:
- jvm_memory_used_bytes{area="heap"} (JVM 메모리 사용량)
- http_server_requests_seconds_count (HTTP 요청 수)
- 그래프 확인 후 Save
ps. 금일에는 새로운 툴들을 사용을 해보지 않았어서 많이 낯설고 어려웠지만, 그래도 어느정도 대략적인 개념은 알게 된 것 같다.
자세한 사용법이랑 유용한 팁 같은 것은 깊게 하나하나 공부해봐야 알 것 같다...
728x90
반응형
LIST
'TIL' 카테고리의 다른 글
9_1.클라우드 및 Docker 개념 학습 (0) | 2025.02.17 |
---|---|
8_5.MSA 애플리케이션 배포 자동화 CI/CD 구축 실습 (0) | 2025.02.17 |
8_3.MSA 데이터 설계 전략 실습 (0) | 2025.02.14 |
8_2.MSA DDD 설계 및 구현 실습 (0) | 2025.02.11 |
8_1.MSA와 모놀리틱 아키텍처 비교와 MSA 장단점 및 도입 시 고려사항 (0) | 2025.02.10 |