Spring Boot 모니터링을 위한 Prometheus & Grafana 실전 가이드
카테고리
프로그래밍/소프트웨어 개발
서브카테고리
DevOps
대상자
- *개발자, DevOps 엔지니어**
- 난이도: 중급 (Spring Boot, Prometheus, Grafana 기본 지식 필요)
핵심 요약
- Prometheus는 시계열 데이터를
pull 방식
으로 수집하는 오픈소스 모니터링 시스템으로,Alert Rule
도 제공 - Grafana는 Prometheus 데이터를 시각화하는 도구로,
차트
,게이지
,테이블
등 다양한 형식 지원 - Spring Boot는
spring-boot-starter-actuator
와micrometer-registry-prometheus
를 사용해 /actuator/prometheus 엔드포인트를 노출
섹션별 세부 요약
1. Prometheus & Grafana 개요
- Prometheus: 시간 간격으로 메트릭 수집, 시계열 데이터 저장
- Grafana: 다양한 데이터 소스에서 데이터를 시각화하여 운영 상태를 직관적으로 표현
- 주요 활용 사례: 시스템 성능 모니터링, 실시간 알림, 트러블슈팅 지원
2. 설치 및 실행
- Prometheus 설치: https://prometheus.io/download/에서 다운로드 후 압축 해제
- Grafana 설치: https://grafana.com/grafana/download에서
.msi
파일 설치 - 실행: Prometheus는
prometheus.exe
실행, Grafana는 기본 포트3000
사용
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 연결:
Connections > Data Sources
에서 Prometheus 선택http://localhost:9090
입력 후Save & test
- 대시보드 생성:
Dashboards > Create dashboard > Add visualization
Metric
선택 후Legend alias
에{{__field.name}}, {{job}}
등 템플릿 사용
결론
- 실무 팁:
- 메트릭 선택: CPU, 메모리, 요청 지연 시간 등 핵심 성능 지표 선택
- 알림 설정: Prometheus의
Alert Rule
을 통해 임계값 설정 및 이메일/Slack 전송 - 대시보드 최적화:
Gauge
,Heatmap
등 적절한 시각화 형식 선택 - 핵심 요약:
Spring Boot + Prometheus + Grafana
조합으로 실시간 모니터링 및 시각화 가능, 시스템 안정성과 트러블슈팅 효율성 극대화