📺 모니터링 환경 구축
Spring Boot 기반의 애플리케이션을 사용 중이라면 Prometheus로 메트릭을 수집한 후 Grafana를 사용하여 대시보드를 구성하여 애플리케이션에 대한 모니터링을 할 수 있다. 아래의 순서대로 모니터링 환경을 단계적으로 구축해보자.
- Spring Boot 프로젝트 생성 (생략)
- Spring Actuator 설정
- Prometheus 설치 및 설정
- Grafana 설치 및 대시보드 구성
📺 Spring Actuator 적용
Spring Boot에는 운영 중인 애플리케이션을 HTTP나 JMX를 이용해서 모니터링하고 관리할 수 있는 기능을 제공하는데 이를 Spring Actuator라 한다. Spring Actuator 적용 방법은 이전 포스트를 참고하자.
[SpringBoot] Spring Actuator
📺 Spring Actuator 란? Spring Boot에는 운영 중인 애플리케이션을 HTTP나 JMX를 이용해서 모니터링하고 관리할 수 있는 기능을 제공하는데 이를 Spring Actuator라 한다. 📺 Spring Actuator 적용 - build.gradle 의
caffeineoverflow.tistory.com
📺 Prometheus란?
Prometheus 관련 설정 및 설치 이전에 Prometheus가 무엇인지 알아보자. Prometheus는 메트릭 기반의 오픈소스 모니터링 시스템으로 메트릭 수집, 시각화, 알림, 서비스 디스커버리 기능을 제공한다. 공식 페이지에서 소개하고 있는 특징을 나열해 보면 다음과 같다.
📺 SpringBoot에 Prometheus 설정
- build.gradle
Prometheus에 대한 의존성을 선언해 준다.
dependencies {
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
}
- application.yml
Spring Actuator의 엔드포인트에 Prometheus를 추가해 준다.
management:
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
📺 Prometheus 설치 및 설정
- Prometheus 설치
https://prometheus.io/download로 이동하여 서버 스펙에 해당하는 파일을 다운로드한다.
다운로드가 완료되면 압축을 푼다.
- prometheus.yml
설정파일인 prometheus.yml 파일을 열어 스프링부트 애플리케이션에 대한 설정을 추가한다.
... 생략
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# 스프링부트에 대한 설정 추가
- job_name: "spring-app"
metrics_path: "/actuator/prometheus"
static_configs:
- targets: ["localhost:8080"]
📺 Prometheus 실행
설정이 완료되었다면 다음 명령어로 Prometheus를 실행한다.
$ ./prometheus
정상 실행이 완료되었다면 브라우저를 실행한 다음 http://localhost:9090을 입력하면 아래와 같은 페이지를 확인할 수 있다.
Prometheus의 그래프 등을 사용하여 시각화할 수 있지만, 보다 훌륭한(?) Grafana를 사용할 경우 멋진 대시보드를 구성할 수 있으니 Prometheus의 사용법에 대해서는 소개하지 않고 넘어가도록 하겠다. 지금까지 스프링부트 프로젝트에 Spring Actuator와 Prometheus 설정 및 설치 방법에 대해서 알아보았다. 다음 시간에는 Grafana 설치를 통해 대시보드를 구성하여 모니터링할 수 있는 방법을 알아보도록 하자.
References.
1. NHN Cloud 기술블로그
2. FINDA 기술블로그
3. Cumulus - 프로메테우스(Prometheus) 알아보기
4. Covenant - 프로메테우스, 그라파나를 이용한 스프링부트 모니터링
5. 만자의 개발일지 - [Prometheus] Prometheus 설치하기
'Spring' 카테고리의 다른 글
[SpringBoot] REST API (0) | 2023.03.11 |
---|---|
[SpringBoot] 모니터링 환경 구축 #3 - Grafana (0) | 2023.03.04 |
[SpringBoot] 모니터링 환경 구축 #1 - Spring Actuator (0) | 2023.02.26 |
[SpringBoot] Bucket4j를 이용한 트래픽 제한 (0) | 2023.02.23 |
[SpringBoot] REST Docs (0) | 2023.02.19 |