• 검색 결과가 없습니다.

Centralized Metrics – Prometheus, Grafana

4. SPRING CLOUD 기반 마이크로 서비스 활용

4.2 S PRING C LOUD 의 컴포넌트 활용

4.2.8 Centralized Metrics – Prometheus, Grafana

애플리케이션을 실행하고, http://localhost:8080/actuator/health 로 서비스가 실행

중이면 다음과 같은 측정값을 제공한다. Status 가 ‘UP’ 이면 건강하다는 의미이다.

http://localhost:8080/actuator 를 통해 Actuator 가 제공하는 endpoint 들을 확인 할 수 있으며, Prometheus Metric 노출 endpoint 가 존재하는지 확인한다.

http://localhost:8080/actuator/prometheus 로 Prometheus 로 수집할 Metric 정보가 노출되는 지 확인 할 수 있다.

http://localhost:8080/actuator/metrics 로 Prometheus 로 수집할 memory, heap, prosessors, threads, classes, thread pools 등의 Metric 정보가 노출되는 지 확인 할 수 있다.

사용자 정의 Metric 을 추가할 수도 있다.

(참고자료) Actuator 에서 제공할 수 있는 endpoint15들은 다음과 같다.

Endpoint ID 설명

auditevents 현 애플리케이션에 대한 Audit Event 정보를 표시한다. AuditEvenRepository bean 이 필요하다.

beans 애플리케이션의 모든 bean 의 목록을 표시한다.

caches 캐시를 표시한다.

conditions 구성 및 자동 구성 클래스에서의 조건과 일치 또는 불일치 이유를 표시한다.

configroups @ConfigurationProperties 의 집합 목록을 표시한다.

env Spring 의 ConfigurableEnvironment 의 환경 변수 값을 표시한다. /env/{name}을 통해 특정 변수의 값을 주회할 수 있다.

flyway 적용된 Flyway 데이터베이스 마이그레이션을 표시한다. 하나 이상의 Flyway bean 이 필요하다.

health 애플리케이션의 상태(health) 정보를 표시한다.

httptrace HTTP trace 정보를 표시한다. HttpTraceRepository bean 이 필요하다.

info 애플리케이션의 정보를 표시한다.

integrationgraph Spring 의 통합 그래프를 표시하며, spring-integration-core 의존성이 필요하다.

loggers 애플리케이션의 loggers 구성을 표시하고 수정한다.

liquibase 적용된 모든 Liquibase 데이터베이스 마이그레이션을 표시한다. 하나 이상의 Liquibase bean 이 필요하다.

metrics 애플리케이션의 metric 정보를 표시한다. (heap, class, gc, thread 등) /metrics/{name}을 통해 개별 metric 을 확인 할 수 있다.

mappings @RequestMapping 경로과 컨트롤러 매핑정보를 표시한다.

scheduledtasks 애플리케이션의 예약된 task 를 표시한다.

sessions Spring Session 저장소에서사용자 세션을 검색 및 삭제할 수 있다.

shutdown 애플리케이션을 안전하게 종료할 수 있다. 기본값은 disabled 이다.

startup ApplicationStartup 에서 수집한 시작단계 데이터를 표시한다.

threaddump heapdump jolokia

logfile 로그파일의 내용을 리턴한다.

prometheus Prometheus 서버로 부터 스크랩될 수 있는 형태로 metric 정보가 노출된다.

micrometer-registry-prometheus 종속성이 필요하다.

4.2.8.1 Prometheus 설치 1. Prometheus 설치

https://prometheus.io/download/ 를 통해서 다운로드 후 압축을 해제한다.

2. Prometheus.yml 설정

Prometheus 가 Actuator endpoint 에 접근할 수 있도록 prometheus.yml 에 아래와 같이 추가한다. Scrape_interval 은 actuator 에 접근하여 데이터를 가져오는

간격이다. scrape_interval: 15s 로 설정하면, 15 초마다 prometheus 가

actuator 에 접근하여 정보를 가져온다. Targets 속성은 Prometheus 가 바라보는 서버 주소이다.

15

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html 참조

3. 실행

윈도우라면, Prometheus.exe 를 실행하고, 리눅스의 경우는 다음과 같이 실행한다.

./Prometheus --config.file=”Prometheus.yml”

웹브라우저에서 http://localhost:9090/graph로 확인한다.

4.2.8.2 Grafana 를 이용한 Prometheus 시각화

Grafana 는 지표(Metric)정보를 쿼리 및 분석하고, 대시보드를 생성하고, 데이터를 시각화하는 툴이다.

1. Grafana 설치

다음 URL 을 참고하여 다운로드 및 설치한다.

https://grafana.com/docs/grafana/latest/installation/windows/

https://grafana.com/docs/grafana/latest/installation/mac/

2. Grafana 실행 및 접속

http://localhost:3000/ 접속한다.

3. Prometheus 설정

Add data source 에서 Prometheus 를 추가한다.

추가한 Prometheus 를 클릭하여 graph 설정한다.

다음은 대시보드의 예이다.