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 | μ€λͺ |
|---|---|---|
| Actuator | http://localhost:8080/management/prometheus | λ©νΈλ¦ μλν¬μΈνΈ |
| Prometheus | http://localhost:9090 | λ©νΈλ¦ μμ§κΈ° |
| Grafana | http://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 | ν¬νΈ | μ€λͺ |
|---|---|---|---|
| Prometheus | http://localhost:9090 | 9090 | λ©νΈλ¦ μμ§κΈ° |
| Grafana | http://localhost:3000 | 3000 | μκ°ν λμ보λ |
| μ ν리μΌμ΄μ | http://localhost:8080 | 8080 | λ©νΈλ¦ μ 곡μ |
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.