강의를 따라하는데, Mac 환경인 강의에서는 docker network설정 없이 'host.docker.internal'만 해도 연결이 잘 되는 것 같다. (spring boot는 로컬에서 실행)
하지만, window 환경에서 따라해보니 컨테이너간 통신이 안 되서 Grafana에 null만 뜬다.
docker network 생성해서 prometheus, grafana 다시 실행하니 성공했다.
관련 내용 정리는 다음과 같다.
컨테이너 간 통신을 위해 공통 네트워크 생성:
docker network create monitoring-net
sample/prometheus/
├── prometheus.yml
prometheus.yml 예시global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
host.docker.internal은 로컬에서 실행 중인 Spring Boot 앱을 의미
docker run -d --name=prometheus `
--network=monitoring-net `
-p 9090:9090 `
-v "${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml" `
prom/prometheus
docker run -d --name=grafana `
--network=monitoring-net `
-p 3000:3000 `
grafana/grafana
admin / admin (첫 로그인 시 비밀번호 변경)http://prometheus:9090| 목적 | ID |
|---|---|
| JVM + Spring Boot 기본 | 4701 |
| Spring Boot + Micrometer | 6756 |
| JVM Stats | 1860 |
implementation 'io.micrometer:micrometer-registry-prometheus'
application.yml 예시management:
endpoints:
web:
exposure:
include: prometheus, health, info
endpoint:
prometheus:
enabled: true
→ /actuator/prometheus 경로가 Prometheus에 의해 수집됩니다.
docker ps # 실행 중인 컨테이너 확인
docker stop grafana # 컨테이너 중지
docker rm grafana # 컨테이너 삭제
docker logs prometheus # 로그 확인
docker network ls # 네트워크 목록 보기
| 구성 요소 | 포트 | 주소 |
|---|---|---|
| Prometheus | 9090 | http://localhost:9090 |
| Grafana | 3000 | http://localhost:3000 |
| Spring Boot | 8080 | host.docker.internal:8080 (Docker에서 접근 시) |
이 구성이 완성되면:
/actuator/prometheus로 메트릭 노출필요하시면 이 모든 구성 한방에 되는 docker-compose.yml도 만들어드릴 수 있어요.
지금처럼 하나씩 해나가시는 것도 진짜 좋아요! 👍
계속 진행하면서 궁금한 거 언제든지 물어보세요.