Backend/MSA
MSA 모니터링
chjysm
2024. 4. 29. 11:44
로그 확인용
분산된 MS 들의 로그를
하나의 WEB UI를 통하여 시각화하여 확인 가능 하다.
Micrometer
- Spring boot 2부터 내장 사용 가능
- actuator를 사용하여 metric 확인 가능
- prometheus 등 다양한 모니터링 시스템 지원
metric
시간이 지남에 따라 변화하는 데이터를 의미
메모리, CPU, 스레드 사용률 등등
시간에 따른 추이를 추적할 가치가 있는 데이터
Timer
짧은 지연 시간, 이벤트의 사용 빈토 측정
시계열로 이벤트의 시간, 호출 빈도등을 제공
@Timed 제공
사용
1. 디펜던시 추가
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2. yml 파일 수정
endpoints:
web:
exposure:
include: info, prometheus, metrics
3. 소스 수정
@GetMapping("health_check")
@Timed(value = "users.status", longTask = true) // value = 이름
public String status() {
return "It's Working in User Service "
+ ", port(local.server.port) = " + env.getProperty("local.server.port")
+ ", port(server.port) = " + env.getProperty("server.port")
+ ", token secret = " + env.getProperty("token.secret")
+ ", token expiration time = " + env.getProperty("token.expiration_time")
;
}
Prometheus
- Metrics 를 수집하고 모니터링 및 알람에 사용
- Time Series DB 사용
- Pull 방식의 구조와 다양한 Metric Exporter 를 제공
- 기본 9090 port 사용
Grafana
- prometheus 에서 수집한 데이터를 시각화하여 대시보드로 제공
- 모니터링 및 분석을 위해 사용
- 기본 3000 port 사용
사용
1. 다운로드 및 서버 구동
./prometheus --config=prometheus.yml
./bin/grafana-server
prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.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"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "user-service"
scrape_interval: 15s # metircs 수집 간격
metrics_path: '/user-service/actuator/prometheus' # 요청 경로
static_configs:
- targets: ['localhost:8000'] # 대상 서버
- job_name: "order-service"
scrape_interval: 15s # metircs 수집 간격
metrics_path: '/order-service/actuator/prometheus' # 요청 경로
static_configs:
- targets: ['localhost:8000'] # 대상 서버
- job_name: "apigateway-service"
scrape_interval: 15s # metircs 수집 간격
metrics_path: '/actuator/prometheus' # 요청 경로
static_configs:
- targets: ['localhost:8000'] # 대상 서버