모니터링 시스템은 기본적으로 데이터 수집 → 통합 → 시각화의 단계로 이루어진다.
Metric
일반적으로 성능, 성과 또는 기타 측정 가능한 요소를 나타내는 데이터를 의미합니다.
시간이 지남에 따라 변화하는 데이터 → CPU , 메모리 사용량 등
Prometheus
시스템 및 서비스의 성능 및 작동을 지속적으로 모니터링할 수 있는 오픈 소스 모니터링 시스템입니다.
특징
- 메트릭 이름과 Key-Value 쌍으로 식별되는 시계열 데이터가 있는 다차원 데이터 모델
- PromQL, 이차 원성을 활용하는 유연한 쿼리 언어
- 기본적으로 Pull 방식으로 다른 곳의 시계열 데이터를 가지고 온다,
- 또한, Push 방식의 데이터도 가져올 수 있도록 하는 Push gateway가 존재하여 두 방식 모두 지원한다.
- 다양한 대시보드와 그래프를 지원함
SpringBoot → Prometheus
SpringBoot는 Metric 수집을 MicroMeter 모듈을 내장한 Actuator가 담당합니다.
Metric은 시간이 흐를수록 계속 쌓이게 되고, Application의 메모리만으로 데이터들을 감당할 수 없어 Metric 전용 외부 DB를 사용하게 되는데 해당 글에서는 Prometheus를 사용합니다.
MicroMeter는 수집한 Metric을 JSON 방식으로 전달합니다. 하지만 프로메테우스는 JSON 데이터를 처리할 수 없어 JSON 데이터를 프로메테우스가 처리 가능한 데이터 형식으로 변환해야 하는데 이를 MicroMeter Prometheus 구현체가 해결해줍니다.
build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-core'
implementation 'io.micrometer:micrometer-registry-prometheus'
}
application.yml
management:
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
management.endpoint.metrics.enabled: true
- Spring Boot 액추에이터(Actuator) 엔드포인트 중에서 **/actuator/metrics**를 사용 가능하게 합니다. 이 엔드포인트는 애플리케이션의 메트릭 정보를 노출합니다.
management.endpoint.prometheus.enabled: true
- Prometheus 형식의 메트릭 엔드포인트를 사용 가능하게 합니다. 이 엔드포인트는 Prometheus 모니터링 시스템과 통합되는 데 사용됩니다.
management.endpoints.web.exposure.include: health, info, metrics, prometheus
- 노출할 엔드포인트를 명시적으로 설정합니다. 이 설정은 기본적으로 /actuator/ 하위 엔드포인트에 적용됩니다.
실행
- http://localhost:8080/actuator/metrics
- 마이크로미터가 수집한 Metric 데이터 (JSON)
- http://localhost:8080/actuator/prometheus
- Metric 데이터를 prometheus 형태로 변형한 데이터
- prometheus는 해당 URL에 접근하여 Metric 데이터를 PULL 한다
참고자료
'Spring' 카테고리의 다른 글
[Spring] log 파일 생성 시 LOG_PATH_IS_UNDEFINED 생성 문제 (0) | 2023.10.27 |
---|---|
Spring Actuator 와 Swagger를 사용할 시 의존성 오류 (0) | 2023.10.26 |
[Spring] JPA N+1 발생 상황과 해결방법 (1) | 2023.10.11 |
QueryDsl를 활용하여 DTO로 바로 만들기 (0) | 2023.08.02 |
Spring Boot JPA 영속성 컨텍스트 (0) | 2023.07.27 |