[Spring Cloud] 모니터링

jsieon97·2023년 3월 23일
0

Hystrix?

마이크로서비스의 전류차단기(Circuit Breaker) 역할을 하는 오픈소스.

Turbine Server

  • 마이크로서비스에 설치된 Hystrix 클라이언트의 스트림을 통합
    • 마이크로서비스에서 생성되는 Hystrix 클라이언트 스트림 메시지를 터빈 서버로 수집

Hystrix Dashboard

  • Hystrix 클라이언트에서 생성하는 스트림을 시각화

Micrometer

Micrometer

  • https://micrometer.io
  • JVM기반의 애플리케이션 Metrics 제공
  • Spring Framework 5, Spring Boot 2부터 Spring의 Metrics 처리
  • Prometheus등의 다양한 모니터링 시스템 지우너

Timer

  • 짧은 지연 시간, 이벤트의 사용 빈도를 측정
  • 시계열로 이벤트의 시간, 호출 빈도 등을 제공
  • @Timed 제공

모니터링 적용

Dependencies

implementation 'io.micrometer:micrometer-registry-prometheus'

property

// application.yml

management:
  endpoints:
    web:
      exposure:
        include: refresh, health, beans, busrefresh, info, metrics, prometheus

Controller

@Timed를 확인하고 싶은 기능에 추가해준다

http://127.0.0.1:{서비스port번호}/actuator/metrics
http://127.0.0.1:{서비스port번호}/actuator/prometheus
위 주소에서 모니터링을 할 수 있다.

Prometheus + Grafana

Prometheus

  • Metrics를 수집하고 모니터링 및 알람에 사용되는 오픈소스 애플리케이션
  • 2016년부터 CNCF에서 관리되는 2번째 공식 프로젝트
    • Level DB -> Time Series Database(TSDB)
  • Pull 방식의 구조와 다양한 Metric Exporter 제공
  • 시계열 DB에 Metrics 저장 -> 조회 가능 (Query)

Grafana

  • 데이터 시각화, 모니터링 및 분석을 위한 오픈소스 애플리케이션
  • 시계열 데이터를 시각화하기 위한 대시보드 제공

설치

prometheus.yml 수정

// prometheus를 등록할 서비스를 입력한다.

...

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: 'user-service'
    scrape_interval: 15s
    metrics_path: '/user-service/actuator/prometheus'
    static_configs:
    - targets: ['localhost:8000']
  - job_name: 'order-service'
    scrape_interval: 15s
    metrics_path: '/order-service/actuator/prometheus'
    static_configs:
    - targets: ['localhost:8000']
  - job_name: 'apigateway-service'
    scrape_interval: 15s
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['localhost:8000']

API Gateway에 /{등록서비스명}/actuator/**를 등록해둔다.

Prometheus 실행

설치한 디렉토리에서 입력

  • MacOS) ./prometheus --config.file=prometheus.yml
  • Windows) .\prometheus.exe

prometheus.yml에 등록된 포트(9090)로 접속

  • 요청 정보를 prometheus에서 알아낸뒤 검색하여 정보를 알아낼 수 있다.

Grafana 실행

설치한 디렉토리에서 실행

  • MacOS) /bin/grafana-server
  • Windows) .\bin\grafana-server.exe

디폴트 계정 admin / admin 으로 접속할 수 있다.

Grafana - Prometheus 연동

profile
개발자로써 성장하는 방법

0개의 댓글