본문으로 건너뛰기
Advertisement

실전 고수 팁 — Actuator, Prometheus, Grafana 서버 메트릭 모니터링

서버 배포 코드만큼 중요한 것이 서버가 살아있는지, 얼마나 건강한지 실시간으로 추적하는 관찰 가능성(Observability) 체계입니다.

1. Spring Boot Actuator 활성화

Actuator는 애플리케이션의 상태(/health), 가동 시간, 스레드 수, JVM 메모리 등을 HTTP 엔드포인트로 노출합니다.

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus' // Prometheus 포맷으로 메트릭 노출
management:
endpoints:
web:
exposure:
include: health, info, metrics, prometheus # 노출할 엔드포인트
endpoint:
health:
show-details: always # 상세 헬스 정보 표시

http://localhost:8080/actuator/prometheus에 접속하면 Prometheus가 수집할 수 있는 텍스트 형식 메트릭이 출력됩니다.

2. Prometheus + Grafana Docker 구성

# docker-compose.monitoring.yml
services:
prometheus:
image: prom/prometheus:v2.51.0
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"

grafana:
image: grafana/grafana:10.4.0
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
# prometheus.yml — 스프링 앱에서 15초마다 메트릭 수집
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080'] # 로컬 스프링 주소

3. 필수 Grafana 대시보드 구성 항목

Grafana에서 데이터소스를 Prometheus로 연결한 후 JVM Micrometer Dashboard(ID: 4701)를 임포트하면 다음 항목들을 즉시 시각화할 수 있습니다.

  • JVM 힙 사용량 → OOM 사전 탐지
  • HTTP 요청 횟수 / 응답 시간 (p95, p99) → API 성능 이상 탐지
  • DB 커넥션 풀 사용률 → 커넥션 포화 사전 탐지
  • JVM 가비지 컬렉션 빈도와 시간 → 메모리 튜닝 지표
Advertisement