Spring Boot 모니터링: Prometheus & Grafana 실전 가이드

Spring Boot 모니터링을 위한 Prometheus & Grafana 실전 가이드

카테고리

프로그래밍/소프트웨어 개발

서브카테고리

DevOps

대상자

  • *개발자, DevOps 엔지니어**
  • 난이도: 중급 (Spring Boot, Prometheus, Grafana 기본 지식 필요)

핵심 요약

  • Prometheus는 시계열 데이터를 pull 방식으로 수집하는 오픈소스 모니터링 시스템으로, Alert Rule도 제공
  • Grafana는 Prometheus 데이터를 시각화하는 도구로, 차트, 게이지, 테이블 등 다양한 형식 지원
  • Spring Bootspring-boot-starter-actuatormicrometer-registry-prometheus를 사용해 /actuator/prometheus 엔드포인트를 노출

섹션별 세부 요약

1. Prometheus & Grafana 개요

  • Prometheus: 시간 간격으로 메트릭 수집, 시계열 데이터 저장
  • Grafana: 다양한 데이터 소스에서 데이터를 시각화하여 운영 상태를 직관적으로 표현
  • 주요 활용 사례: 시스템 성능 모니터링, 실시간 알림, 트러블슈팅 지원

2. 설치 및 실행

3. Spring Boot 설정

  • build.gradle에 추가:

```groovy

implementation 'org.springframework.boot:spring-boot-starter-actuator'

implementation 'io.micrometer:micrometer-registry-prometheus'

```

  • application.yaml 설정:

```yaml

management:

endpoints:

web:

exposure:

include: prometheus

metrics:

export:

prometheus:

enabled: true

```

  • 엔드포인트 확인: http://localhost:8080/actuator/prometheus

4. Prometheus 설정

  • prometheus.yml 구성:

```yaml

scrape_configs:

- job_name: 'spring-actuator'

metrics_path: '/actuator/prometheus'

static_configs:

- targets: ['localhost:8080']

```

  • 실행 및 확인: Status > Target health에서 수집 대상 상태 확인

5. Grafana 설정 및 대시보드 구성

  • Grafana 접속: http://localhost:3000 접속 후 admin/admin 로그인
  • Prometheus 연결:
  1. Connections > Data Sources에서 Prometheus 선택
  2. http://localhost:9090 입력 후 Save & test
  • 대시보드 생성:
  1. Dashboards > Create dashboard > Add visualization
  2. Metric 선택 후 Legend alias{{__field.name}}, {{job}} 등 템플릿 사용

결론

  • 실무 팁:
  • 메트릭 선택: CPU, 메모리, 요청 지연 시간 등 핵심 성능 지표 선택
  • 알림 설정: Prometheus의 Alert Rule을 통해 임계값 설정 및 이메일/Slack 전송
  • 대시보드 최적화: Gauge, Heatmap 등 적절한 시각화 형식 선택
  • 핵심 요약: Spring Boot + Prometheus + Grafana 조합으로 실시간 모니터링 및 시각화 가능, 시스템 안정성과 트러블슈팅 효율성 극대화