
Spring Boot 애플리케이션을 실제로 운영하려면 단순 로그 출력만으로는 부족하다.
로그를 모아서 검색하고, 성능과 장애 상황을 시계열로 추적하고, 대시보드로 한눈에 보고 싶다.
그 역할을 나눠서 담당하는 것이 바로 ELK(로그), Prometheus + Grafana(모니터링) 조합이다.
ELK 스택은 다음 세 가지로 구성된 로그 수집·분석 도구 묶음이다.
즉, 한 줄로 정리하면:
애플리케이션 로그 → Logstash → Elasticsearch → Kibana로 시각화
로그 흐름은 보통 이렇게 잡는다.
Spring Boot → Logstash → Elasticsearch → Kibana
order-service-YYYY.MM.dd 같은 패턴)예시 설정:
input {
tcp {
port => 5000
codec => json
}
}
output {
elasticsearch {
hosts => ["elasticsearch:9200"]
index => "order-service-%{+YYYY.MM.dd}"
}
}
정리:
input
tcp
port => 5000 : Spring Boot가 로그를 보내는 포트codec => json : 들어오는 로그가 JSON 형식이라는 뜻output
elasticsearch
hosts : Elasticsearch 주소 (도커라면 서비스 이름 사용 가능)
index : 저장할 인덱스 이름 패턴
"order-service-%{+YYYY.MM.dd}"order-service-2025.12.02curl로 직접 쿼리할 수 있다.
curl -X GET "http://localhost:9200/<인덱스>/_search" \
-H 'Content-Type: application/json' -d '
{
"query": {
...
}
}'
<인덱스>에 order-service-*처럼 패턴 사용 가능curl -X GET "http://localhost:9200/order-service-*/_search" \
-H 'Content-Type: application/json' -d '
{
"query": {
"match": {
"level": "WARN"
}
}
}'
curl -X GET "http://localhost:9200/order-service-*/_search" \
-H 'Content-Type: application/json' -d '
{
"query": {
"match": {
"message": "Order created"
}
}
}'
curl -X GET "http://localhost:9200/order-service-*/_search" \
-H 'Content-Type: application/json' -d '
{
"query": {
"range": {
"@timestamp": {
"gte": "now-1h",
"lte": "now"
}
}
}
}'
curl -X GET "http://localhost:9200/order-service-*/_search" \
-H 'Content-Type: application/json' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "level": "INFO" } },
{ "match": { "message": "Order list" } }
]
}
}
}'
curl -X GET "http://localhost:9200/order-service-*/_search" \
-H 'Content-Type: application/json' -d '
{
"size": 3,
"query": {
"match_all": {}
}
}'
Kibana에서 Elasticsearch 인덱스를 바라보게 설정해야 Discover에서 로그를 볼 수 있다.
http://localhost:5601 접속order-service-*@timestamp 선택인덱스가 안 보이면 Elasticsearch 인덱스 목록을 확인한다.
curl http://localhost:9200/_cat/indices?v
운영 환경에서는 단순히 “로그만 보는 것”으로는 모자라다.
그래서 보통 모니터링 시스템을 이렇게 나눈다.
수집
통합
시각화
Prometheus와 Grafana는 이 모니터링 파이프라인에서
역할을 맡는다.
Prometheus는 오픈 소스 모니터링 및 알림 도구다.
주요 특징:
Spring Boot와 연결할 때는 Actuator + Micrometer를 통해 메트릭을 노출하고,
Prometheus가 주기적으로 그 엔드포인트를 긁어 가는 구조다.
메트릭 흐름은 이렇게 보면 된다.
Spring Boot (Actuator + Micrometer)
↓
/actuator/prometheus
↓
Prometheus 스크래핑
Micrometer
Actuator
/actuator/health, /actuator/metrics, /actuator/prometheus 등 노출/actuator/prometheus에서 Prometheus 형식으로 메트릭을 출력예시로 /actuator/metrics에서 노출되는 메트릭 이름 일부:
{
"names": [
"application.ready.time",
"disk.free",
"hikaricp.connections",
"http.server.requests",
"jvm.memory.used",
"logback.events",
"process.cpu.usage",
"system.cpu.count",
"tomcat.sessions.active.current"
]
}
Prometheus는 이 메트릭들을 일정 주기로 가져가서, 과거 이력까지 포함해 저장하는 DB 역할을 한다.
기본 설정 예시:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['order-service:8080']
정리:
global.scrape_interval: 15s
scrape_configs
job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
targets: ['order-service:8080']
동작 순서:
http://order-service:8080/actuator/prometheus 요청접속 주소: http://localhost:9090
기본 흐름:
Execute 클릭자주 보는 예시:
| 예시 PromQL | 설명 |
|---|---|
http_server_requests_seconds_count | HTTP 요청 수 |
jvm_memory_used_bytes | JVM 메모리 사용량 |
process_cpu_usage | 애플리케이션 CPU 사용률 |
system_cpu_usage | 시스템 전체 CPU 사용률 |
rate(http_server_requests_seconds_count[1m]) | 최근 1분 간 초당 요청 수 |
Prometheus UI는 주로
용도로 쓰고, 실제 대시보드는 주로 Grafana에서 구성한다.
Grafana는 데이터 시각화 및 대시보드 도구다.
특징:
다양한 데이터 소스 지원
대시보드 구성
알림
Prometheus와 함께 쓸 때는 보통 이렇게 생각하면 된다.
Prometheus = 메트릭 DB
Grafana = 그 DB를 예쁘게 보여주는 대시보드
구성 흐름:
Spring Boot → Prometheus → Grafana
프로비저닝을 사용하면 Grafana가 시작될 때 자동으로 데이터 소스를 등록할 수 있다.
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
필드 설명:
name
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
접속 주소: http://localhost:3000
기본 계정: admin / admin (최초 로그인 시 비밀번호 변경)
Prometheus 데이터 소스 존재 여부 확인Save & test 버튼으로 연결 확인Add new panel 클릭rate(http_server_requests_seconds_count[1m])이렇게 한두 개 패널만 만들어도
같은 기본 모니터링 대시보드를 빠르게 구성할 수 있다.
ELK
Prometheus
Grafana
운영 환경을 준비할 때
나눠서 설계하면 구조가 훨씬 깔끔해지고, 장애 대응과 성능 분석도 훨씬 수월해진다.