
서비스를 운영하다 보면 이런 상황을 겪게 됩니다:
➡️ 이럴 때 실시간으로 서버와 서비스 상태를 수집/분석할 수 있어야 합니다.
그래서 사용하는 것이 바로 Prometheus + Grafana 입니다.
[ 대상 시스템 (Redis, MySQL, Spring 서비스 등) ]
↓
[ Exporter - 메트릭을 수집해서 노출 ]
↓
[ Prometheus - 메트릭을 주기적으로 수집하고 저장 ]
↓
[ Grafana - 시각화 및 대시보드 제공 ]
| 구성 요소 | 역할 |
|---|---|
| Prometheus | 메트릭 수집기. Exporter로부터 데이터를 주기적으로 긁어와 저장 |
| Grafana | 시각화 도구. Prometheus 데이터를 바탕으로 대시보드 생성 |
| Exporter | 시스템/서비스 상태를 Prometheus가 이해할 수 있는 형식으로 노출 |
prometheus.yml 설정global:
scrape_interval: 10s
scrape_configs:
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8080']
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
version: '3.7'
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3000:3000"
volumes:
- grafana-storage:/var/lib/grafana
volumes:
grafana-storage:
| 주소 | 설명 |
|---|---|
http://localhost:9090 | Prometheus 웹 UI |
http://localhost:3000 | Grafana 대시보드 (기본 로그인: admin / admin) |
up # 각 타겟이 살아있는지 여부
node_cpu_seconds_total # 노드 CPU 사용량
container_memory_usage_bytes # 컨테이너 메모리 사용량
Prometheus와 Grafana로 모니터링 시스템을 구축했다면, 이제 진짜 중요한 건 "무엇을 모니터링할 것인가?"입니다.
이번 편에서는 실제 컨테이너, 서버, 데이터베이스의 상태를 수집하기 위한 Exporter들과 cAdvisor를 소개합니다.
Prometheus는 모든 시스템의 메트릭 구조를 알지 못합니다.
그래서 각 시스템의 상태를 Prometheus가 이해할 수 있는 표준 메트릭 포맷으로 변환해주는 중간 역할이 필요합니다.
이걸 Exporter라고 합니다.
[ 대상 시스템 (Redis, MySQL, 서버 등) ] → [ Exporter ] → [ Prometheus ]
| Exporter | 모니터링 대상 | 기본 포트 | 설명 |
|---|---|---|---|
| node-exporter | 리눅스 서버 상태 (CPU, Mem 등) | 9100 | 서버 단위로 자원 사용률을 수집 |
| redis-exporter | Redis 상태 | 9121 | 메모리, 커넥션, hit rate 등 |
| mysql-exporter | MySQL 상태 | 9104 | 쿼리 성능, 연결 수 등 |
| cadvisor | Docker 컨테이너 자원 사용량 | 8080 | 컨테이너별 CPU, Memory, Disk 등 |
아래는 대표 Exporter를 Docker Compose로 구성한 예시입니다.
docker-compose.yml 예시 (추가 부분)version: '3.7'
services:
# 컨테이너 자원 모니터링
cadvisor:
image: gcr.io/cadvisor/cadvisor
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
# 리눅스 서버 자원 모니터링
node-exporter:
image: prom/node-exporter
ports:
- "9100:9100"
# Redis 상태 모니터링
redis-exporter:
image: oliver006/redis_exporter
ports:
- "9121:9121"
environment:
REDIS_ADDR: redis:6379
# MySQL 상태 모니터링
mysql-exporter:
image: prom/mysqld-exporter
ports:
- "9104:9104"
environment:
DATA_SOURCE_NAME: root:password@(mysql:3306)/
scrape_configs:
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8080']
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
- job_name: 'redis'
static_configs:
- targets: ['redis-exporter:9121']
- job_name: 'mysql'
static_configs:
- targets: ['mysql-exporter:9104']
| Exporter | 주요 메트릭 예시 |
|---|---|
node-exporter | node_memory_MemAvailable_bytes, node_cpu_seconds_total |
cadvisor | container_memory_usage_bytes, container_cpu_usage_seconds_total |
redis-exporter | redis_connected_clients, redis_memory_used_bytes |
mysql-exporter | mysql_global_status_threads_connected, mysql_global_status_queries |
cAdvisor(Container Advisor)는 컨테이너의 리소스 사용량을 실시간으로 추적하는 Exporter입니다.
| 도구 | 설명 |
|---|---|
cAdvisor | 컨테이너별 자원 사용량을 수집하는 Exporter |
node-exporter | 서버 자체의 자원 상태 수집 |
redis-exporter | Redis 내부 상태 수집 |
mysql-exporter | MySQL 쿼리 및 연결 상태 수집 |
Prometheus | Exporter로부터 메트릭 수집 및 저장 |
Grafana | Prometheus 데이터를 시각화 |