Windows에서 Prometheus + Grafana 설정

Kim jisu·2025년 4월 4일

TIL

목록 보기
28/43

강의를 따라하는데, Mac 환경인 강의에서는 docker network설정 없이 'host.docker.internal'만 해도 연결이 잘 되는 것 같다. (spring boot는 로컬에서 실행)

하지만, window 환경에서 따라해보니 컨테이너간 통신이 안 되서 Grafana에 null만 뜬다.
docker network 생성해서 prometheus, grafana 다시 실행하니 성공했다.

관련 내용 정리는 다음과 같다.


🧱 0. 사전 준비

설치 필요:


🐳 1. Docker 네트워크 생성

컨테이너 간 통신을 위해 공통 네트워크 생성:

docker network create monitoring-net

📦 2. Prometheus 설정

📁 디렉토리 구성 예시

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 앱을 의미


🐳 Prometheus 컨테이너 실행

docker run -d --name=prometheus `
  --network=monitoring-net `
  -p 9090:9090 `
  -v "${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml" `
  prom/prometheus

📊 3. Grafana 실행

docker run -d --name=grafana `
  --network=monitoring-net `
  -p 3000:3000 `
  grafana/grafana

🧪 4. 접속 및 설정

✅ Prometheus 접속

✅ Grafana 접속


⚙️ Grafana에서 Prometheus 데이터 소스 연결

  1. Grafana 왼쪽 메뉴 → ⚙️ Data Sources
    • Add data source → Prometheus 선택
  2. URL 입력:
    http://prometheus:9090
  3. Save & Test 클릭 → ✅ “Data source is working”

📈 5. 대시보드 추가

  1. 왼쪽 메뉴 → 📊 Dashboards → + Import
  2. 인기 있는 대시보드 ID 입력:
목적ID
JVM + Spring Boot 기본4701
Spring Boot + Micrometer6756
JVM Stats1860
  1. 데이터 소스로 Prometheus 선택 후 Import!

💡 6. Spring Boot 설정 (추가)

📦 의존성 (Gradle 기준)

implementation 'io.micrometer:micrometer-registry-prometheus'

📁 application.yml 예시

management:
  endpoints:
    web:
      exposure:
        include: prometheus, health, info
  endpoint:
    prometheus:
      enabled: true

→ /actuator/prometheus 경로가 Prometheus에 의해 수집됩니다.


🧼 7. 정리 명령어 모음

docker ps                 # 실행 중인 컨테이너 확인
docker stop grafana       # 컨테이너 중지
docker rm grafana         # 컨테이너 삭제
docker logs prometheus    # 로그 확인
docker network ls         # 네트워크 목록 보기

📎 참고 구조 요약

구성 요소포트주소
Prometheus9090http://localhost:9090
Grafana3000http://localhost:3000
Spring Boot8080host.docker.internal:8080 (Docker에서 접근 시)

✅ 마무리

이 구성이 완성되면:

  • Spring Boot 애플리케이션 → /actuator/prometheus로 메트릭 노출
  • Prometheus → 15초 간격으로 수집
  • Grafana → 대시보드에서 시각화

필요하시면 이 모든 구성 한방에 되는 docker-compose.yml도 만들어드릴 수 있어요.
지금처럼 하나씩 해나가시는 것도 진짜 좋아요! 👍
계속 진행하면서 궁금한 거 언제든지 물어보세요.

profile
Dreamer

0개의 댓글