Post

JHipster λͺ¨λ‹ˆν„°λ§

JHipster λͺ¨λ‹ˆν„°λ§

πŸ”„ λͺ¨λ‹ˆν„°λ§ 3μš”μ†Œ 연동 ꡬ쑰

1. Spring Boot Actuator (λ©”νŠΈλ¦­ μƒμ‚°μž)

1
2
3
4
5
6
7
8
9
10
11
12
# application.yml
management:
  endpoints:
    web:
      base-path: /management
      exposure:
        include: ['health', 'info', 'prometheus', 'metrics']
  metrics:
    export:
      prometheus:
        enabled: true
        step: 60

μ—­ν• :

  • μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ—μ„œ λ©”νŠΈλ¦­ 데이터λ₯Ό μƒμ„±ν•˜κ³  λ…ΈμΆœ
  • /management/prometheus μ—”λ“œν¬μΈνŠΈλ‘œ Prometheus ν˜•μ‹μ˜ λ©”νŠΈλ¦­ 제곡
  • JVM, HTTP, μ‹œμŠ€ν…œ λ©”νŠΈλ¦­ μžλ™ μˆ˜μ§‘

2. Prometheus (λ©”νŠΈλ¦­ μˆ˜μ§‘ 및 μ €μž₯)

1
2
3
4
5
6
# prometheus.yml
scrape_configs:
  - job_name: 'prometheus'
    metrics_path: /management/prometheus
    static_configs:
      - targets: ['localhost:8080']

μ—­ν• :

  • Actuatorμ—μ„œ μƒμ„±λœ λ©”νŠΈλ¦­μ„ 주기적으둜 μŠ€ν¬λž˜ν•‘ (κΈ°λ³Έ 15초 간격)
  • λ©”νŠΈλ¦­ 데이터λ₯Ό μ‹œκ³„μ—΄ λ°μ΄ν„°λ² μ΄μŠ€μ— μ €μž₯
  • PromQL둜 데이터 뢄석 κ°€λŠ₯

3. Grafana (μ‹œκ°ν™” 및 λŒ€μ‹œλ³΄λ“œ)

1
2
3
4
5
# datasource.yml
datasources:
  - name: Prometheus
    type: prometheus
    url: http://localhost:9090

μ—­ν• :

  • Prometheusμ—μ„œ μˆ˜μ§‘λœ λ©”νŠΈλ¦­μ„ μ‹œκ°ν™”
  • JVM, HTTP, μ‹œμŠ€ν…œ λ©”νŠΈλ¦­ λŒ€μ‹œλ³΄λ“œ 제곡
  • μ‹€μ‹œκ°„ λͺ¨λ‹ˆν„°λ§ 및 μ•Œλ¦Ό μ„€μ •

πŸ”— 데이터 흐름

1
2
3
4
5
Spring Boot App (Actuator)
        ↓ /management/prometheus
Prometheus (μŠ€ν¬λž˜ν•‘)
        ↓ λ©”νŠΈλ¦­ μ €μž₯
Grafana (μ‹œκ°ν™”)

πŸ“Š μ‹€μ œ λͺ¨λ‹ˆν„°λ§λ˜λŠ” λ©”νŠΈλ¦­

JVM λ©”νŠΈλ¦­

  • jvm_memory_used_bytes : λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰
  • jvm_gc_pause_seconds : κ°€λΉ„μ§€ μ»¬λ ‰μ…˜ μ‹œκ°„
  • jvm_threads_live : ν™œμ„± μŠ€λ ˆλ“œ 수

HTTP λ©”νŠΈλ¦­

  • http_server_requests_seconds_count : HTTP μš”μ²­ 수
  • http_server_requests_seconds_sum : 응닡 μ‹œκ°„ 합계
  • http_server_requests_seconds_max : μ΅œλŒ€ 응닡 μ‹œκ°„

μ‹œμŠ€ν…œ λ©”νŠΈλ¦­

  • system_cpu_usage : CPU μ‚¬μš©λ₯ 
  • process_memory_rss_bytes : ν”„λ‘œμ„ΈμŠ€ λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰
  • process_open_fds : μ—΄λ¦° 파일 λ””μŠ€ν¬λ¦½ν„° 수

πŸš€ μ‹€ν–‰ 방법

1
2
3
4
5
# 1. μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ‹€ν–‰
./gradlew bootRun

# 2. λͺ¨λ‹ˆν„°λ§ μŠ€νƒ μ‹€ν–‰
docker-compose -f src/main/docker/monitoring.yml up -d

🌐 μ ‘κ·Ό URL

μ„œλΉ„μŠ€URLμ„€λͺ…
Actuatorhttp://localhost:8080/management/prometheusλ©”νŠΈλ¦­ μ—”λ“œν¬μΈνŠΈ
Prometheushttp://localhost:9090λ©”νŠΈλ¦­ μˆ˜μ§‘κΈ°
Grafanahttp://localhost:3000μ‹œκ°ν™” λŒ€μ‹œλ³΄λ“œ

βœ… μ΄λ ‡κ²Œ Actuator β†’ Prometheus β†’ Grafana μˆœμ„œλ‘œ 데이터가 흐λ₯΄λ©΄μ„œ μ™„μ „ν•œ λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ„ κ΅¬μ„±ν•©λ‹ˆλ‹€.


🐳 Prometheus & Grafana Docker μ„€μ • 상세 뢄석

1. Docker Compose μ„€μ • (monitoring.yml)

πŸ” Prometheus μ„œλΉ„μŠ€

1
2
3
4
5
6
7
8
9
snuheras-prometheus:
  image: prom/prometheus:v2.38.0
  volumes:
    - ./prometheus/:/etc/prometheus/
  command:
    - '--config.file=/etc/prometheus/prometheus.yml'
  ports:
    - 127.0.0.1:9090:9090
  network_mode: 'host'

μ£Όμš” μ„€μ •:

  • 이미지: Prometheus v2.38.0 (μ•ˆμ • 버전)
  • λ³Όλ₯¨ 마운트: 둜컬 ./prometheus/ β†’ μ»¨ν…Œμ΄λ„ˆ /etc/prometheus/
  • 포트: 9090 (둜컬호슀트만 μ ‘κ·Ό κ°€λŠ₯)
  • λ„€νŠΈμ›Œν¬: host λͺ¨λ“œ (둜컬 μ„œλΉ„μŠ€μ™€ ν†΅μ‹ μš©)

πŸ“Š Grafana μ„œλΉ„μŠ€

1
2
3
4
5
6
7
8
9
10
11
snuheras-grafana:
  image: grafana/grafana:9.1.0
  volumes:
    - ./grafana/provisioning/:/etc/grafana/provisioning/
  environment:
    - GF_SECURITY_ADMIN_PASSWORD=admin
    - GF_USERS_ALLOW_SIGN_UP=false
    - GF_INSTALL_PLUGINS=grafana-piechart-panel
  ports:
    - 127.0.0.1:3000:3000
  network_mode: 'host'

μ£Όμš” μ„€μ •:

  • 이미지: Grafana 9.1.0
  • λ³Όλ₯¨ 마운트: 둜컬 ./grafana/provisioning/ β†’ μ»¨ν…Œμ΄λ„ˆ /etc/grafana/provisioning/
  • ν™˜κ²½λ³€μˆ˜:
    • GF_SECURITY_ADMIN_PASSWORD=admin: κ΄€λ¦¬μž λΉ„λ°€λ²ˆν˜Έ
    • GF_USERS_ALLOW_SIGN_UP=false: μ‚¬μš©μž κ°€μž… λΉ„ν™œμ„±ν™”
    • GF_INSTALL_PLUGINS=grafana-piechart-panel: 파이차트 ν”ŒλŸ¬κ·ΈμΈ μ„€μΉ˜

2. Prometheus μ„€μ • (prometheus.yml)

βš™οΈ κΈ€λ‘œλ²Œ μ„€μ •

1
2
3
4
5
global:
  scrape_interval: 15s      # λ©”νŠΈλ¦­ μˆ˜μ§‘ 간격
  evaluation_interval: 15s  # κ·œμΉ™ 평가 간격
  external_labels:
    monitor: 'jhipster'     # μ™ΈλΆ€ 라벨

🎯 μŠ€ν¬λž˜ν•‘ μ„€μ •

1
2
3
4
5
6
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s                    # 5μ΄ˆλ§ˆλ‹€ μˆ˜μ§‘
    metrics_path: /management/prometheus    # Actuator μ—”λ“œν¬μΈνŠΈ
    static_configs:
      - targets: ['localhost:8080']        # νƒ€κ²Ÿ μ• ν”Œλ¦¬μΌ€μ΄μ…˜

μˆ˜μ§‘λ˜λŠ” λ©”νŠΈλ¦­:

  • JVM λ©”νŠΈλ¦­ (λ©”λͺ¨λ¦¬, GC, μŠ€λ ˆλ“œ)
  • HTTP λ©”νŠΈλ¦­ (μš”μ²­ 수, 응닡 μ‹œκ°„)
  • μ‹œμŠ€ν…œ λ©”νŠΈλ¦­ (CPU, λ©”λͺ¨λ¦¬, 파일 λ””μŠ€ν¬λ¦½ν„°)

3. Grafana λ°μ΄ν„°μ†ŒμŠ€ μ„€μ • (datasource.yml)

πŸ”— Prometheus μ—°κ²° μ„€μ •

1
2
3
4
5
6
7
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://localhost:9090
    isDefault: true
    editable: true

μ£Όμš” μ„€μ •:

  • νƒ€μž…: Prometheus
  • μ ‘κ·Ό 방식: Proxy (Grafanaκ°€ 쀑계)
  • URL: Prometheus μ„œλ²„ μ£Όμ†Œ
  • κΈ°λ³Έ λ°μ΄ν„°μ†ŒμŠ€: true
  • νŽΈμ§‘ κ°€λŠ₯: true

4. Grafana λŒ€μ‹œλ³΄λ“œ μ„€μ • (dashboard.yml)

πŸ“ˆ λŒ€μ‹œλ³΄λ“œ ν”„λ‘œλΉ„μ €λ‹

1
2
3
4
5
6
7
8
providers:
  - name: 'Prometheus'
    orgId: 1
    type: file
    disableDeletion: false
    editable: true
    options:
      path: /etc/grafana/provisioning/dashboards

μ„€μ • λ‚΄μš©:

  • 쑰직 ID: 1 (κΈ°λ³Έ 쑰직)
  • νƒ€μž…: 파일 기반
  • μ‚­μ œ λΉ„ν™œμ„±ν™”: false
  • νŽΈμ§‘ κ°€λŠ₯: true
  • 경둜: /etc/grafana/provisioning/dashboards

5. 디렉토리 ꡬ쑰

1
2
3
4
5
6
7
8
9
10
11
src/main/docker/
β”œβ”€β”€ monitoring.yml                    # Docker Compose μ„€μ •
β”œβ”€β”€ prometheus/
β”‚   └── prometheus.yml               # Prometheus μ„€μ •
└── grafana/
    └── provisioning/
        β”œβ”€β”€ datasources/
        β”‚   └── datasource.yml       # λ°μ΄ν„°μ†ŒμŠ€ μ„€μ •
        └── dashboards/
            β”œβ”€β”€ dashboard.yml        # λŒ€μ‹œλ³΄λ“œ ν”„λ‘œλΉ„μ €λ‹
            └── JVM.json            # JVM λ©”νŠΈλ¦­ λŒ€μ‹œλ³΄λ“œ

6. μ‹€ν–‰ 방법

πŸš€ λͺ¨λ‹ˆν„°λ§ μŠ€νƒ μ‹œμž‘

1
2
3
4
5
6
7
8
# λͺ¨λ‹ˆν„°λ§ 도ꡬ듀 μ‹€ν–‰
docker-compose -f src/main/docker/monitoring.yml up -d

# 둜그 확인
docker-compose -f src/main/docker/monitoring.yml logs -f

# μ„œλΉ„μŠ€ μƒνƒœ 확인
docker-compose -f src/main/docker/monitoring.yml ps

πŸ›‘ λͺ¨λ‹ˆν„°λ§ μŠ€νƒ 쀑지

1
2
3
4
5
# μ„œλΉ„μŠ€ 쀑지
docker-compose -f src/main/docker/monitoring.yml down

# λ³Όλ₯¨κΉŒμ§€ μ‚­μ œ (데이터 μ‚­μ œ)
docker-compose -f src/main/docker/monitoring.yml down -v

7. λ„€νŠΈμ›Œν¬ μ„€μ •

🌐 Host λ„€νŠΈμ›Œν¬ λͺ¨λ“œ

1
network_mode: 'host'

μž₯점:

  • λ‘œμ»¬μ—μ„œ μ‹€ν–‰ 쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜κ³Ό 직접 톡신
  • 포트 λ§€ν•‘ λΆˆν•„μš”
  • λ„€νŠΈμ›Œν¬ μ„±λŠ₯ ν–₯상

μ£Όμ˜μ‚¬ν•­:

  • MacOSμ—μ„œλŠ” host.docker.internal μ‚¬μš© ν•„μš”
  • λ³΄μ•ˆμƒ ν”„λ‘œλ•μ…˜μ—μ„œλŠ” μ‚¬μš© μ§€μ–‘

8. μ ‘κ·Ό URL 및 포트

μ„œλΉ„μŠ€URLν¬νŠΈμ„€λͺ…
Prometheushttp://localhost:90909090λ©”νŠΈλ¦­ μˆ˜μ§‘κΈ°
Grafanahttp://localhost:30003000μ‹œκ°ν™” λŒ€μ‹œλ³΄λ“œ
μ• ν”Œλ¦¬μΌ€μ΄μ…˜http://localhost:80808080λ©”νŠΈλ¦­ 제곡자

9. λ³΄μ•ˆ 고렀사항

πŸ”’ 개발 ν™˜κ²½ μ„€μ •

  • 127.0.0.1: μ ‘λ‘μ‚¬λ‘œ 둜컬 μ ‘κ·Όλ§Œ ν—ˆμš©
  • κΈ°λ³Έ 인증 μ—†μŒ (개발용)
  • Host λ„€νŠΈμ›Œν¬ λͺ¨λ“œ μ‚¬μš©

πŸš€ ν”„λ‘œλ•μ…˜ ν™˜κ²½ ꢌμž₯사항

1
2
3
4
5
6
7
8
9
# ν”„λ‘œλ•μ…˜μš© μ„€μ • μ˜ˆμ‹œ
services:
  prometheus:
    ports:
      - "9090:9090"  # 127.0.0.1 제거
    networks:
      - monitoring
    environment:
      - PROMETHEUS_CONFIG_FILE=/etc/prometheus/prometheus.yml

μ΄λ ‡κ²Œ Dockerλ₯Ό 톡해 Prometheus와 Grafanaκ°€ μ™„μ „νžˆ μžλ™ν™”λœ λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ„ κ΅¬μ„±ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€!

This post is licensed under CC BY 4.0 by the author.