Files

309 lines
7.9 KiB
Markdown

# ChocoMae 성능 모니터링 & Serverless 마이그레이션 준비
이 패키지는 현재 운영 중인 EC2 인스턴스(t3a.medium, Ubuntu 24.04.1 LTS)에서 **1주일 동안 24시간 성능 지표를 수집**하고, 이를 바탕으로 **Serverless 아키텍처로의 마이그레이션을 준비**하기 위한 도구입니다.
---
## 📋 패키지 구성
| 파일 | 설명 |
|------|------|
| `chocomae-24h-monitoring.sh` | **메인 모니터링 스크립트** - 1분 간격으로 지표 수집 |
| `analyze_monitoring.py` | **데이터 분석 스크립트** - 수집된 CSV를 분석 및 시각화 |
| `MONITORING_SETUP.md` | **설정 및 설치 가이드** |
| `README.md` | **이 파일** - 전체 개요 및 사용 가이드 |
---
## 🚀 빠른 시작
### 1단계: 서버에 스크립트 배포
```bash
# 로컬에서 서버로 복사
scp chocomae-24h-monitoring.sh ubuntu@<ec2-instance>:/home/ubuntu/
scp analyze_monitoring.py ubuntu@<ec2-instance>:/home/ubuntu/
# 또는 서버에서 직접 다운로드
ssh ubuntu@<ec2-instance>
cd /home/ubuntu
# 스크립트를 서버에 준비
```
### 2단계: 필수 패키지 설치
```bash
ssh ubuntu@<ec2-instance>
# 사전 요구사항 확인 및 설치
sudo apt-get update
sudo apt-get install -y sysstat curl python3 python3-pandas
# sudo 비밀번호 없이 mariadb 명령 실행 설정
sudo visudo
# 다음 라인 추가:
# ubuntu ALL=(ALL) NOPASSWD: /usr/bin/mariadb
```
### 3단계: 모니터링 시작
```bash
# 방법 1: 백그라운드 실행
/home/ubuntu/chocomae-24h-monitoring.sh &
# 방법 2: systemd 서비스로 자동 실행 (추천)
# MONITORING_SETUP.md 참조
```
### 4단계: 1주일 후 데이터 분석
```bash
# 수집된 데이터 분석
python3 analyze_monitoring.py /home/ubuntu/chocomae-monitoring
# 또는 직접 CSV 파일 확인
ls -lh /home/ubuntu/chocomae-monitoring/
head -100 /home/ubuntu/chocomae-monitoring/chocomae-20260921.log
```
---
## 📊 수집 항목
### WEB (Apache)
- **CPU 사용률** (%)
- **메모리 사용량** (MB)
- **Busy/Idle Workers 수** (개)
- **Keep-Alive 연결 수** (개)
- **누적 요청 수** (개)
### WAS (PHP-FPM)
- **CPU 사용률** (%)
- **메모리 사용량** (MB)
- **프로세스 개수** (개)
### DB (MariaDB)
- **CPU 사용률** (%)
- **메모리 사용량** (MB)
- **현재 연결 수** (개)
- **최대 사용된 연결 수** (개)
- **실행 중인 스레드 수** (개)
- **Slow Query 누적 수** (개)
### 시스템
- **전체 CPU 사용률** (%)
- **전체 메모리 사용률** (%)
- **여유 메모리** (GB)
- **디스크 사용률** (%)
- **디스크 여유 공간** (GB)
- **디스크 IO (읽기/쓰기)** (MB/s)
---
## 📈 분석 방법
### 1. 자동 분석 (권장)
```bash
python3 analyze_monitoring.py /home/ubuntu/chocomae-monitoring > analysis_report.txt
```
**생성되는 분석 항목:**
- ✓ 시스템 전체 통계
- ✓ 시간대별 분석 (피크 타임 파악)
- ✓ 요일별 분석
- ✓ Apache/PHP/MariaDB 성능 분석
- ✓ 디스크 성능 분석
- ✓ 이상 탐지 (anomaly detection)
- ✓ **Serverless 마이그레이션 권고사항**
### 2. 수동 분석
```bash
# CSV 파일 직접 확인
tail -100 /home/ubuntu/chocomae-monitoring/chocomae-20260921.log
# Excel/Spreadsheet에서 분석
# 또는 Python/R에서 커스텀 분석
```
---
## 🎯 Serverless 마이그레이션 체크리스트
분석 결과를 바탕으로 다음을 검토하세요:
### 아키텍처 설계
- [ ] **동시 연결 분석** - Lambda concurrency 설정
- [ ] **처리량 분석** - 필요한 Lambda 인스턴스 수
- [ ] **메모리 요구사항** - Lambda 메모리 할당
- [ ] **실행 시간** - Lambda 타임아웃 설정
### 데이터베이스 마이그레이션
- [ ] **RDS Aurora 도입** (또는 RDS Aurora Serverless)
- [ ] **Connection Pooling** (RDS Proxy 사용)
- [ ] **Slow Query 최적화**
- [ ] **데이터베이스 인덱스 검증**
### 애플리케이션 수정
- [ ] **파일 업로드/다운로드** (S3로 이동)
- [ ] **세션 관리** (DynamoDB 또는 ElastiCache)
- [ ] **환경 변수 관리** (Secrets Manager)
- [ ] **로깅 및 모니터링** (CloudWatch)
### 성능 최적화
- [ ] **API Gateway 스로틀링** 설정
- [ ] **Lambda 시작 시간 최적화** (Cold Start)
- [ ] **데이터베이스 성능 튜닝**
- [ ] **캐싱 전략** (CloudFront, ElastiCache)
---
## 💾 데이터 보관 및 백업
### 모니터링 데이터 위치
```
/home/ubuntu/chocomae-monitoring/
├── chocomae-20260921.log # 일별 CSV 파일
├── chocomae-20260922.log
└── ...
```
### 데이터 내보내기
```bash
# 모든 데이터를 하나의 CSV로 병합
cat /home/ubuntu/chocomae-monitoring/chocomae-*.log > all_monitoring_data.csv
# 또는 head 제거 후 병합
head -1 /home/ubuntu/chocomae-monitoring/chocomae-20260921.log > all_data.csv
tail -n +2 /home/ubuntu/chocomae-monitoring/chocomae-*.log >> all_data.csv
```
### S3로 백업 (선택)
```bash
aws s3 sync /home/ubuntu/chocomae-monitoring/ s3://your-bucket/monitoring-data/
```
---
## 🔧 문제 해결
### Q: 스크립트가 Permission Denied 오류 발생
```bash
chmod +x /home/ubuntu/chocomae-24h-monitoring.sh
```
### Q: MariaDB 연결 실패
```bash
# sudo 설정 확인
sudo visudo
# 다음 라인 추가:
# ubuntu ALL=(ALL) NOPASSWD: /usr/bin/mariadb
```
### Q: iostat 명령 없음
```bash
sudo apt-get install -y sysstat
```
### Q: Apache /server-status 접근 불가
```bash
sudo a2enmod status
sudo apache2ctl configtest
sudo systemctl restart apache2
```
### Q: 로그 파일이 생성되지 않음
```bash
# 디렉토리 권한 확인
ls -la /home/ubuntu/
mkdir -p /home/ubuntu/chocomae-monitoring
chmod 755 /home/ubuntu/chocomae-monitoring
```
---
## 📋 분석 리포트 해석 가이드
### 1. 시스템 전체 분석
```
시스템 CPU: 평균 15.5%, 최대 45.2%
→ 피크 시간에 CPU 45% 사용 = 여유 있음 (t3a.medium 4 vCPU)
```
### 2. 시간대별 분석
```
14:00 시스템 CPU: 평균 32%, 최대 52%
→ 주중 오후 1시~3시 피크 (원래 예상한 시간대)
```
### 3. Apache 분석
```
Busy Workers - 평균 12, 최대 28
→ 최대 28 workers 사용, 전체 설정된 workers 수와 비교
```
### 4. MariaDB 분석
```
현재 연결 - 평균 8, 최대 35
Slow Queries - 누적 250개
→ 연결 수는 양호, 하지만 Slow Query 최적화 필요
```
### 5. Serverless 권고사항
```
• 피크 시간대: 14:00 (CPU: 45.2%)
• 동시 연결 수: 평균 8, 최대 35
• Lambda 메모리 할당 제안: 1024MB
• RDS Aurora Serverless 추천
```
---
## 📞 지원 및 문의
### 문제 발생 시
1. **로그 확인**: `/home/ubuntu/chocomae-monitoring/monitor.log` (systemd 실행 시)
2. **스크립트 로그**: 콘솔 출력 확인
3. **시스템 로그**: `journalctl -u chocomae-monitoring` (systemd 서비스)
### 추가 정보
- Apache 상태: `curl http://localhost/server-status?auto`
- MariaDB 상태: `mysql -e "SHOW GLOBAL STATUS;"`
- 디스크 사용량: `df -h`
- 프로세스 상태: `ps aux | grep -E 'apache|php|mariadb'`
---
## 📚 참고자료
### 현재 구성 (EC2 기준)
- **인스턴스**: t3a.medium (2 vCPU, 4 GB RAM)
- **OS**: Ubuntu 24.04.1 LTS
- **서비스**: Apache, PHP-FPM, MariaDB
### 관련 문서
- `MONITORING_SETUP.md` - 상세 설치 및 설정 가이드
- `chocomae-24h-monitoring.sh` - 모니터링 스크립트 (주석 참고)
- `analyze_monitoring.py` - 분석 스크립트 (함수별 설명)
---
## ✅ 체크리스트
모니터링 시작 전 다음을 확인하세요:
- [ ] 필수 패키지 설치 완료 (sysstat, curl, python3)
- [ ] sudo 비밀번호 설정 (MariaDB 접근용)
- [ ] Apache `/server-status?auto` 정상 작동
- [ ] MariaDB 접근 테스트 완료
- [ ] 디렉토리 권한 확인 (`/home/ubuntu/chocomae-monitoring`)
- [ ] 스크립트 실행 권한 확인 (`chmod +x`)
- [ ] 백그라운드 실행 또는 systemd 서비스 구성 완료
---
**마지막 업데이트**: 2026-09-21
**문서 작성자**: 자동 생성 스크립트 및 분석 도구