Spring Boot 애플리케이션의 상태와 동작을 모니터링하고 관리할 수 있도록 다양한 기능을 제공하는 모듈. 이를 통해 애플리케이션의 상태를 실시간으로 확인하거나 진단 정보를 쉽게 수집할 수 있음
엔드포인트: 다양한 엔드포인트를 통해 애플리케이션의 상태 및 메트릭을 제공함
/actuator/health: 애플리케이션의 상태를 확인함(Up/Down)/actuator/metrics: JVM, CPU, 메모리, 힙 사용량 등 다양한 메트릭 제공/actuator/env: 환경 변수 및 설정 속성 확인/actuator/loggers: 애플리케이션 로거 수준 변경 및 확인/actuator/beans: Spring 컨텍스트에서 관리되는 빈 정보/actuator/threaddump: 현재 스레드 덤프 정보 제공/actuator/mappings: 애플리케이션의 URL 매핑 정보/actuator/info: 사용자 정의 애플리케이션 정보 출력/actuator/httptrace: 최근 HTTP 요청 및 응답을 추적메트릭 수집
상태 점검(Health Checks)
HealthIndicator 인터페이스를 통해 애플리케이션의 상태를 모니터링HealthIndicator를 구현하여 맞춤형 상태 점검 로직을 추가할 수도 있음설정 및 커스터마이징
implementation 'org.springframework.boot:spring-boot-starter-actuator'
spring.application.name=sample
server.port=8080
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
모든 엔드포인트를 노출하는 것은 개발 및 테스트때는 유용할 수 있으나 운영 환경에서는 보안 위험을 증가시킬 수 있음

/actuator로 접근하면 내용을 확인할 수 있다.
각각의 링크에서 상세 정보 확인 가능.
오픈소스 시스템 모니터링 및 경고 도구.
시계열 데이터(Time-Series Data)를 수집하고 쿼리하는데 최적화되어 있음
확장성, 강력한 데이터 모델, 표현력있는 쿼리 언어(PromQL)가 장점
시계열 데이터 저장
Pull 방식 데이터 수집
PromQL (Prometheus Query Language)
rate(http_requests_total[5m]): 지난 5분동안의 HTTP 요청 속도sum by (status)(rate(http_requests_total[1m])): 상태별 HTTP 요청 속도의 합계다양한 Exporter
경고 및 알림
시각화
확장성
장점
- 오픈소스이면서도 강력한 기능을 제공함.
- 높은 표현력을 가진 PromQL 제공.
- 다양한 Exporter로 광범위한 모니터링 가능.
- 경고 및 알림 기능 내장.
- Grafana와 연동해 시각화를 쉽게 구현.
단점
- 분산 데이터 저장 기능이 기본적으로 지원되지 않음.
- Push 방식보다는 Pull 방식에 최적화.
- 큰 데이터 볼륨을 처리할 때 스토리지 관리가 필요함.
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
management.endpoint.prometheus.enabled=true
강의에서 위의 방법을 제공하였지만 deprecated된 속성임.
# prometheus 관련 엔드포인트만 활성화
management.endpoints.web.exposure.include=prometheus
# 모든 엔드포인트 활성화
management.endpoints.web.exposure.include=*
/acutator로 접근 시 prometheus 항목을 찾아볼 수 있다.

프로젝트 루트에 작성.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
9090포트로 실행해줬다.

9090으로 접속 시 prometheus 대시보드를 확인할 수 있다.


애플리케이션 상태를 확인할 수 있다.
오픈소스 데이터 시각화 및 모니터링 플랫폼
다양한 데이터 소스를 연결하여 대시보드 형태로 데이터를 시각화하고 분석할 수 있음
Prometheus와 같은 시계열 데이터베이스와 자주 함께 사용되며 클라우드 환경이나 DevOps 도구로 많이 활용됨
대시보드
경고
사용자 관리 및 권한 제어
플러그인 생태계
장점
- 강력한 시각화 도구: 사용자 정의 가능한 다양한 시각화 스타일 제공
- 다양한 데이터 소스 지원
- 유연성: 플러그인과 템플릿을 통해 확장 가능
- 오픈소스
단점
- 초기 설정의 복잡성
- 리소스 사용량: 대규모 데이터 소스를 처리할 때 높은 메모리와 CPU를 소모할 수 있음
Docker로 3000번 포트에서 실행함.
localhost:3000으로 접속하면 로그인 후 대시보드를 확인할 수 있다.
기본 id, password는 admin

아까의 Prometheus를 추가해준다.


data source 목록에서 추가한 prometheus를 찾을 수 있다.
build a dashboard 클릭
https://grafana.com/grafana/dashboards/ 에서 적당한 대시보드를 골라 import해준다.

시각화된 데이터를 확인할 수 있다.
Grafana Labs에서 개발한 오픈소스 로그 집계 시스템
Prometheus와 유사한 방식으로 작동하지만 로그 데이터를 위한 시스템이라는 점에서 차이가 있음
로그를 효율적으로 수집, 저장, 검색할 수 있도록 설계됨
로그의 시계열 데이터베이스
경량 설계
라벨 기반 검색
Prometheus와의 연동
Grafana와 통합
수집 및 저장
쿼리 언어 (LogQL)
분산 및 확장성
1.애플리케이션 로그 분석: Kubernetes, Docker 컨테이너, 마이크로서비스의 애플리케이션 로그 수집 및 분석
2. 문제 디버깅: 특정 시간대에 발생한 오류 로그를 검색하고 관련된 메트릭과 연관 분석
3. 운영 모니터링: CPU/메모리 메트릭과 로그 데이터를 연계하여 시스템 상태를 포괄적으로 모니터링
4. Kubernetes 환경: Kubernetes의 Pod, 네임스페이스, 애플리케이션 등에서 생성된 로그를 효율적으로 수집하고 분석
implementation 'com.github.loki4j:loki-logback-appender:1.5.1'
<configuration>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>app=my-app,host=${HOSTNAME}</pattern>
</label>
<message class="com.github.loki4j.logback.JsonLayout" />
</format>
</appender>
<root level="DEBUG">
<appender-ref ref="LOKI" />
</root>
</configuration>
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/analytics/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
# reporting_enabled: false
3100 포트로 실행해줬다.
3100으로 접속 시 ready 상태를 확인할 수 있다.


대시보드 없이도 Explore에서 쿼리로 데이터를 필터링 해 볼 수 있다
