๐ฏ ์ต์ข ๋ชฉํ: ์ด๋ ๊ฒ ๋๋ค!
Spring Boot์์ ์๋ฒ ์ํ ์ ๋ณด๋ฅผ ์ซ์๋ก ๋ฝ์๋ด๊ณ
→ Prometheus๊ฐ ๊ทธ๊ฑธ ์์งํ๊ณ
→ Grafana๊ฐ ๋ณด๊ธฐ ์ข๊ฒ ๊ทธ๋ํ๋ก ๋ณด์ฌ์ค๋๋ค.
โ Step 1: Spring Boot Actuator๊ฐ "์๋ฒ ์ํ ๋ฐ์ดํฐ"๋ฅผ ๋ฝ๋๋ค
์: ์ด๋ฐ ๋ฐ์ดํฐ๋ค์ด ์๋์ผ๋ก ์์ฑ๋จ
ํญ๋ชฉ | ์ค๋ช |
jvm.memory.used | JVM ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ |
http.server.requests | HTTP ์์ฒญ ์, ์๋ต ์๊ฐ |
system.cpu.usage | CPU ์ฌ์ฉ๋ฅ |
process.uptime | ์๋ฒ ์คํ ์๊ฐ |
logback.events | ๋ก๊ทธ ๋ฐ์ ์ |
๐ ์ด ๋ฐ์ดํฐ๋ /actuator/prometheus๋ผ๋ URL์ ์ซ์ + ์ค๋ช ํ์์ผ๋ก ๋ ธ์ถ๋ฉ๋๋ค:
โ Step 2: Prometheus๊ฐ /actuator/prometheus์ 15์ด๋ง๋ค ์ ๊ทผํด์ ๋ฐ์ดํฐ๋ฅผ ์์ง
Prometheus๋ "์ผ, ๋ ์ง๊ธ ์ํ ์ด๋?" ํ๊ณ 15์ด๋ง๋ค ์์ฒญ์ ๋ณด๋ ๋๋ค.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
๐ก ์ฌ๊ธฐ์ host.docker.internal์ ๋ก์ปฌ์์ ๋์ด Spring ์๋ฒ๋ฅผ ๋์ปค ์ปจํ ์ด๋ ์์์ ์ ๊ทผํ ์ ์๊ฒ ํด์ฃผ๋ ํค์๋์ ๋๋ค (๋งฅ/์๋์ฐ ๊ธฐ์ค)
๐ ์ด ๋ธ๋ก์ ์๋ฏธ:
์ค์ | ํญ๋ชฉ์ค๋ช |
job_name: 'spring-boot-app' | ์ด ์ค์ ๋ธ๋ก์ Prometheus ๋ด๋ถ์์ ๊ตฌ๋ถํ๊ธฐ ์ํ ์ด๋ฆ (๋์๋ณด๋ ๋ฑ์์ ์ด ์ด๋ฆ์ผ๋ก ๊ทธ๋ฃนํ๋จ) |
metrics_path: '/actuator/prometheus' | ๋ฉํธ๋ฆญ์ ์์งํ HTTP ๊ฒฝ๋ก (Spring Boot๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ด ๊ฒฝ๋ก์์ ๋ ธ์ถํจ) |
targets: ['host.docker.internal:8080'] | ๋ฐ์ดํฐ๋ฅผ ์์งํ ์ค์ ๋์ ์๋ฒ (์ฌ๊ธฐ์๋ ๋ก์ปฌ์์ 8080์ผ๋ก ์คํ ์ค์ธ Spring Boot ์๋ฒ) |
โ Step 3: Grafana๊ฐ Prometheus์์ ์์ง๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํ
Grafana๋ ์ง์ ๋ฐ์ดํฐ๋ฅผ ์์งํ์ง ์๊ณ ,
โก Prometheus์ ์์ธ ๋ฐ์ดํฐ๋ฅผ ์๊ฐ์ ์ผ๋ก ๋ณด์ฌ์ฃผ๋ ์ญํ ์
๋๋ค.
- ์: CPU ์ฌ์ฉ๋ฅ → ์ ๊ทธ๋ํ
- ์: API ์๋ต ์๋ → ์๊ฐ๋๋ณ ๊บพ์์ ๊ทธ๋ํ
- ์: ์๋ฌ ์๋ต ๋น์จ → ๋๋ ์ฐจํธ
๐ ์ด๋ฐ ์์ผ๋ก ๋ณด์ฌ์ง๋๋ค
โ Step 4: Grafana์์ Dashboard ๋ง๋ค๊ธฐ
- http://localhost:3001 ์ ์
- ๋ก๊ทธ์ธ (๊ธฐ๋ณธ: admin / admin)
- ์ข์ธก ๋ฉ๋ด → โ๏ธ Data Sources → Prometheus ์ถ๊ฐ
- ์ข์ธก ๋ฉ๋ด → ๐ Dashboards → Import
- Dashboard ID: 4701 (Micrometer + Spring Boot ๋์๋ณด๋)
- ํ์ธํ๋ฉด ์๋์ผ๋ก ๊ทธ๋ํ๋ค์ด ์์ฑ๋ฉ๋๋ค!
โจ ์ ๋ฆฌ ์์
๋จ๊ณ | ์ค๋ช |
1๏ธโฃ | Spring Boot์ actuator, micrometer ์ถ๊ฐ → /actuator/prometheus์์ ์ํ ๊ณต๊ฐ |
2๏ธโฃ | Prometheus๊ฐ ์ด URL์ ์ ๊ธฐ์ ์ผ๋ก ๋ฐฉ๋ฌธํด์ ๋ฐ์ดํฐ ์์ง |
3๏ธโฃ | Grafana๊ฐ Prometheus์์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ด |
4๏ธโฃ | Grafana ๋์๋ณด๋์์ ๊ทธ๋ํ๋ก ์๊ฐํ๋จ |
๐ ์ค์ ์ด์์์ ์ด๋ฐ ๊ฒ๋ ๋ณผ ์ ์์ด์
- ์ด๋ API๊ฐ ์ ์ผ ๋๋ฆฐ์ง
- 5xx ์๋ฌ๊ฐ ๋ง์ด ๋ฐ์ํ API๋ ๋ฌด์์ธ์ง
- ๋ฉ๋ชจ๋ฆฌ ๋์๊ฐ ์๋์ง
- ์๋ฒ๊ฐ ๋ค์ด๋๊ธฐ ์ ์ด์์งํ๋ ๋ฌด์์ด์๋์ง
๐ฆ 1๋จ๊ณ: Spring Boot ์ค์
โ ์์กด์ฑ ์ถ๊ฐ (build.gradle)
// APM (Monitoring)
implementation 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
โก application.properties ์ค์
# APM
management.endpoints.web.exposure.include=health,info,prometheus
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
๐ ์ด๋ ๊ฒ ํ๋ฉด http://localhost:8080/actuator/prometheus์์ ๋ฉํธ๋ฆญ์ด ๋ ธ์ถ๋ฉ๋๋ค.
Spring Security์๋ ์ถ๊ฐ
http
.authorizeHttpRequests((auth) -> auth
.requestMatchers("/actuator/**").permitAll() // ํ๋ก๋ฉํ
์ฐ์ค
๐ฆ 2๋จ๊ณ: Prometheus + Grafana Docker๋ก ์คํ
๐ docker-compose.yml
version: '3'
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3001:3000" # 3000๋ฒ ํฌํธ๋ Next.js๊ฐ ์ฐ๊ณ ์์ผ๋ฏ๋ก 3001๋ก ๋ณ๊ฒฝ
volumes:
- grafana-storage:/var/lib/grafana
volumes:
grafana-storage:
๐ 3๋จ๊ณ: Prometheus ์ค์ ํ์ผ
๐ prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-boot-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['host.docker.internal:8080']
๐ host.docker.internal์ ๋์ปค ์ปจํ ์ด๋์์ ๋ก์ปฌ ํธ์คํธ(์๋์ฐ/๋งฅ ๊ธฐ์ค)๋ฅผ ๋ฐ๋ผ๋ณผ ๋ ์ฌ์ฉํฉ๋๋ค.
๋ฆฌ๋ ์ค๋ ๋์ 172.17.0.1 ์ฌ์ฉํ๊ฑฐ๋ network_mode: host ํ์ํฉ๋๋ค.
๐ 4๋จ๊ณ: ์คํ
docker-compose up -d
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3001
๐ 5๋จ๊ณ: Grafana ๋์๋ณด๋ ๊ตฌ์ฑ
- Grafana ์ ์ (ID: admin / PW: admin)
- ์ข์ธก "โ๏ธ ์ค์ → Data Sources"
- Prometheus ์ ํ
- URL: http://prometheus:9090
- "Import Dashboard"
- ํ ํ๋ฆฟ ID: 4701 (Spring Boot with Micrometer)
- โ๏ธ ๋ฐ์ดํฐ๊ฐ ์๋์ผ๋ก ๋ค์ด์ค๊ธฐ ์์ํฉ๋๋ค
'Project > Boilerplate' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
AWS EC2+RDS SpringBoot+MySQL ๋ฐฐํฌ (2) | 2025.04.15 |
---|---|
์ด๋ฏธ์ง ์ ์ฅ์ฉ EC2 + S3 ๋ฒํท ์ฐ๋ (1) | 2025.04.14 |
๋ก์ปฌ ๊ฐ๋ฐ์์ ๋ฐฐํฌ, ๊ฐ๋ฐ ํ๊ฒฝ ๋ถ๋ฆฌํ๊ธฐ (0) | 2025.04.10 |
Mock ํ ์คํธ ์ค ์ํฐํฐ id ๋ฐ SecurityContextHolder ์ค์ (0) | 2025.04.02 |
WebMvcTest + Spring REST doc + Swagger ์ ์ฉ ( 2 / 2 - Spring REST doc + Swagger ) (0) | 2025.03.29 |