Spring Boot Actuator, Prometheus, Grafana 간단 정리

Soohyeok Kim·2025년 6월 3일
  • Spring Boot Actuator
  • Prometheus
  • Grafana
  • 포트 정리
  • 관계와 데이터 흐름
  • /actuator/prometheus vs Grafana

Spring Boot Actuator

Spring Boot에서 애플리케이션의 내부 상태 및 메트릭 데이터를 노출해주는 라이브러리.

애플리케이션의 헬스 체크, HTTP 요청/응답 기록, DB 커넥션 풀, 쓰레드 풀, 등록된 빈 등 다양한 정보를 REST API 형태로 제공함.

메트릭 데이터란?

서버나 애플리케이션의 상태(성능 지표)를 시간에 따라 수집한 데이터.

  • JVM 메모리 사용량
  • CPU 사용률
  • DB Connection Pool 상태
  • HTTP 요청 수 / 평균 응답시간
  • 등등

프로메테우스가 이 데이터를 시계열 데이터(Time Series) 형태로 저장해서 시간에 따른 변화를 분석 가능.

주요 엔드포인트

  • /actuator/health: 애플리케이션 상태 (켜져있나)
  • /actuator/info: 애플리케이션 빌드/버전 정보
  • /actuator/prometheus: 프로메테우스가 데이터를 가져갈 수 있도록 메트릭을 노출
  • /actuator/metrics: 제공하는 메트릭들을 확인가능

주요 설정

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus
  metrics:
    export:
      prometheus:
        enabled: true
  • management.endpoints.web.exposure.include: 외부로 노출할 엔드포인트 설정 (보안을 위해 꼭 필요한 것만 열어줘야 함)
    • /prometheus endpoint는 프로메테우스가 GET요청을 보내서 데이터를 수집해야하니까 열어줘야함
  • management.metrics.export.prometheus.enabled: 프로메테우스가 수집할 데이터 포맷을 활성화시킴. 없어도 됨. (default: true)

결론적으로 endpoint를 사용하려면 활성화하고 노출시켜줘야 함

Prometheus

시계열(Time Series) 데이터베이스.
Actuator가 제공하는 메트릭 데이터를 주기적으로 수집함. (Pull 방식)

JVM 메모리, CPU 사용량, HTTP 요청, DB 커넥션 풀 상태 등 다양한 지표를 시계열로 저장해서 분석할 수 있음.

동작 방식

# ./prometheus.yml
global:
  scrape_interval: 5s

scrape_configs:
  - job_name: 'spring-actuator'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8080'] 
  1. prometheus.yml 설정 파일에 수집 대상을 등록
  2. 일정 주기 scrape_interval 로 메트릭을 수집해 DB에 저장
  3. 웹 UI(9090)에서 메트릭 쿼리(PromQL)를 직접 실행해 볼 수 있긴함

Grafana

프로메테우스가 수집한 메트릭 데이터를 시각화하는 대시보드 도구.

여러 지표를 한눈에 보고 성능 변화 추세, 병목 현상 등을 직관적으로 파악할 수 있음.

실질적인 모니터링은 그라파나를 통해 확인

동작 방식

  1. Grafana(3000포트)는 Prometheus(9090포트)를 데이터 소스로 등록.
  2. Prometheus로부터 데이터를 가져와 그래프, 차트, 테이블로 표현.

포트 정리

포트서비스특징 및 설명
8080Spring Boot Actuator엔드포인트 제공 (/actuator/health, /actuator/prometheus)
9090(기본포트)Prometheus메트릭 쿼리, 수집 상태 확인 UI (Text 형식)
3000(기본포트)Grafana프로메테우스가 수집한 데이터로 대시보드 시각화

관계와 데이터 흐름

[Spring Boot App (8080)] < [Prometheus (9090)] < [Grafana (3000)]

단계설명
1. Spring Boot Actuator/actuator/prometheus 엔드포인트에서 JVM 메모리, DB 커넥션, HTTP 요청 등 실시간 데이터를 Prometheus 형식으로 노출
2. Prometheus/actuator/prometheus에 주기적으로 HTTP GET 요청을 보내 데이터를 수집 후 DB에 저장
3. GrafanaPrometheus 데이터를 가져와 시각화 (그래프, 차트, 테이블)

/actuator/prometheus vs Grafana

항목/actuator/prometheus (8080)Grafana (3000)
데이터실시간 Raw 데이터Prometheus DB에서 가져온 시계열 데이터
특징텍스트 형태, 개발자 전용그래프/차트로 시각화
목적Prometheus가 데이터 수집벤치마킹 대시보드, 알림, 분석
profile
백엔드 개발자

0개의 댓글