📌 주제: Spring Boot Actuator + Prometheus + Grafana로 모니터링 환경 구성하기
1️⃣ Spring Boot Actuator란?
- Spring Boot에서 제공하는 운영 및 모니터링 기능을 쉽게 사용할 수 있게 해주는 라이브러리.
- /actuator/health, /actuator/metrics 등 다양한 endpoint를 통해 시스템 상태 확인 가능.
- 대표적인 endpoint:
- /actuator/health: 애플리케이션 상태
- /actuator/metrics: 메트릭 지표들 (메모리, CPU, GC 등)
- /actuator/httptrace, /actuator/env 등
🔧 의존성 추가
implementation 'org.springframework.boot:spring-boot-starter-actuator'
🔧 application.yml 설정
management:
endpoints:
web:
exposure:
include: health, metrics, prometheus
endpoint:
prometheus:
enabled: true
2️⃣ Prometheus란?
- 시계열(Time-series) 기반의 모니터링 툴.
- 애플리케이션의 /actuator/prometheus endpoint를 정기적으로 스크랩하여 데이터를 수집함.
- Pull 방식으로 데이터를 가져오는 것이 특징.
🔧 prometheus.yml 설정 예시
global:
scrape_interval: 5s
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080'] # 로컬에서 Docker 쓸 때
3️⃣ Grafana란?
- Prometheus에 쌓인 메트릭 데이터를 시각화해주는 대시보드 도구.
- 다양한 Panel, Alert 기능 제공.
- Prometheus를 데이터 소스로 연결하여 실시간 모니터링 가능.
🎨 주요 사용법
- Prometheus 연결: Configuration > Data Sources > Add data source > Prometheus
- 대시보드 템플릿 가져오기 (ex. Spring Boot JVM Dashboard ID: 4701)
- 직접 대시보드 구성 가능 (CPU, Memory, HTTP 요청수 등)
💡 느낀 점
- Actuator와 Prometheus만으로도 웬만한 서비스 상태 체크는 충분했고,
- Grafana까지 붙이면 실시간 대시보드 모니터링이 가능해서 운영 효율이 확실히 올라갈 것 같다.
- 특히 /actuator/prometheus 엔드포인트 덕분에 Spring Boot 앱과 Prometheus의 연동이 매우 간단했음.
- 추후에는 Alert 설정이나 Slack 연동 적용 실습을 통해 진행해 볼 것이다.