
사이드 프로젝트를 하면서 늘 고민이 있었습니다.
“내 서비스가 잘 동작하는 건 알겠는데, 성능이나 장애는 어떻게 확인하지?”
특히 EC2 프리티어 환경에서 돌리는 서비스라서,
이런 부분이 늘 불안했습니다.
그래서 이번에는 Observability(관찰 가능성) 환경을 직접 구축하기로 했습니다.
결론적으로, 로그 + 메트릭 + 트레이스를 하나로 묶어보고 싶다는 니즈가 제일 컸습니다.
첫 단계는 docker-compose로 관찰 가능성 스택을 띄우는 것이었습니다.
이번 편에서는 핵심인 Prometheus, Grafana, Loki, Tempo만 올렸습니다.
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
grafana:
image: grafana/grafana
ports:
- "3000:3000"
loki:
image: grafana/loki:2.9.2
ports:
- "3100:3100"
tempo:
image: grafana/tempo:2.3.1
ports:
- "3200:3200"
여기서는 Postgres, Promtail, OTEL Collector 같은 것들은 잠시 빼고, “관찰용 스택이 정상 기동되는지”만 확인했습니다.

Spring Boot Actuator를 켜고 Prometheus 엔드포인트를 노출했습니다.
# application-local.yml
management:
endpoints:
web:
exposure:
include:
- health
- info
- prometheus
metrics:
distribution:
percentiles-histogram:
http.server.requests: true
percentiles:
http.server.requests: 0.5, 0.95, 0.99
http://localhost:8080/actuator/prometheus접속 시,
http_server_requests_seconds_count같은 메트릭이 보이면 성공입니다.

Prometheus 설정에서 Spring Boot 애플리케이션을 스크랩 대상으로 등록합니다.
# prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
처음에는
localhost:8080을 썼다가 실패했는데,
Docker 컨테이너에서 접근할 때는host.docker.internal을 써야 정상적으로 UP 상태가 됐습니다.

http://prometheus:9090
http_server_requests_seconds_count 조회 → 그래프 출력
간단히 ApacheBench로 부하를 줬습니다.
ab -n 1000 -c 50 http://localhost:8080/
localhost 대신 host.docker.internal을 써야 함.이번 1편에서는,
까지 다뤘습니다.