7.6 KiB
7.6 KiB
ChocoMae 모니터링 - 빠른 시작 가이드
📌 개요
목적: EC2 인스턴스(t3a.medium)에서 1주일간 24시간 성능 지표를 수집하여 Serverless 마이그레이션 준비
모니터링 대상:
- WEB: Apache
- WAS: PHP-FPM
- DB: MariaDB
- System: CPU, Memory, Disk
수집 주기: 1분 간격 (1주일 = ~10,000개 레코드)
🚀 설치 (5분)
1. 서버 접속 및 필수 패키지 설치
ssh ubuntu@<your-ec2-instance>
# 필수 패키지 설치
sudo apt-get update
sudo apt-get install -y sysstat curl python3 python3-pandas
# iostat 확인 (DISK IO 수집용)
which iostat
2. Sudo 설정 (MariaDB 비밀번호 없이 접근)
sudo visudo
# 다음 라인을 파일 끝에 추가:
ubuntu ALL=(ALL) NOPASSWD: /usr/bin/mariadb
3. 스크립트 배포
# 로컬에서 실행
scp chocomae-24h-monitoring.sh ubuntu@<your-ec2-instance>:/home/ubuntu/
scp analyze_monitoring.py ubuntu@<your-ec2-instance>:/home/ubuntu/
# 또는 서버에서 직접 생성
# (파일 내용을 복사하여 /home/ubuntu/chocomae-24h-monitoring.sh 생성)
4. 권한 설정
ssh ubuntu@<your-ec2-instance>
chmod +x /home/ubuntu/chocomae-24h-monitoring.sh
mkdir -p /home/ubuntu/chocomae-monitoring
⚙️ 실행 방법 (3가지)
방법 1: 간단하게 백그라운드 실행 (즉시 시작)
/home/ubuntu/chocomae-24h-monitoring.sh &
방법 2: Systemd 서비스로 자동 관리 (권장)
# 서비스 파일 생성
sudo tee /etc/systemd/system/chocomae-monitoring.service > /dev/null <<'EOF'
[Unit]
Description=ChocoMae 24/7 Monitoring
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu
ExecStart=/home/ubuntu/chocomae-24h-monitoring.sh
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# 서비스 등록 및 시작
sudo systemctl daemon-reload
sudo systemctl enable chocomae-monitoring.service
sudo systemctl start chocomae-monitoring.service
# 상태 확인
sudo systemctl status chocomae-monitoring.service
방법 3: Cron으로 부팅 시 자동 실행
crontab -e
# 다음 라인 추가:
@reboot /home/ubuntu/chocomae-24h-monitoring.sh > /home/ubuntu/chocomae-monitoring/monitor.log 2>&1 &
📊 모니터링 확인
실행 확인
# 프로세스 확인
ps aux | grep chocomae-24h-monitoring
# 로그 파일 확인
ls -lh /home/ubuntu/chocomae-monitoring/
# 실시간 로그 보기
tail -f /home/ubuntu/chocomae-monitoring/chocomae-$(date +%Y%m%d).log
로그 형식
timestamp,apache_cpu,apache_mem,...
2026-09-21 14:30:00,5.2,180,50,...
2026-09-21 14:31:00,6.1,185,52,...
📈 데이터 분석 (1주일 후)
1. 자동 분석 (권장)
# Python 분석 스크립트 실행
python3 /home/ubuntu/analyze_monitoring.py /home/ubuntu/chocomae-monitoring
# 결과를 파일로 저장
python3 /home/ubuntu/analyze_monitoring.py /home/ubuntu/chocomae-monitoring > report.txt
2. 생성되는 분석 항목
✅ 시스템 전체 통계 (CPU, 메모리 평균/최대/최소) ✅ 시간대별 분석 (피크 타임 파악) ✅ 요일별 분석 ✅ Apache 성능 (Workers, Keep-Alive, 처리량) ✅ MariaDB 성능 (연결, 스레드, Slow Queries) ✅ PHP-FPM 성능 ✅ 디스크 성능 (용량, IO) ✅ 이상 탐지 (CPU/메모리 스파이크) ✅ 🎯 Serverless 마이그레이션 권고사항
3. 수동 분석
# CSV 데이터 병합
cat /home/ubuntu/chocomae-monitoring/chocomae-*.log > all_data.csv
# Excel/Sheets에서 분석 또는 Python으로 커스텀 분석
python3 << 'EOF'
import pandas as pd
df = pd.read_csv('all_data.csv')
# 피크 타임 확인
df['hour'] = pd.to_datetime(df['timestamp']).dt.hour
print(df.groupby('hour')['system_cpu_usage_percent'].mean())
# 최대 메모리 사용
print(f"Max memory: {df['system_mem_usage_percent'].max()}%")
EOF
🎯 Serverless 마이그레이션 준비 체크리스트
분석 결과로 다음을 검토하세요:
데이터베이스
- 동시 연결 수 확인 → RDS Aurora 메모리 크기 결정
- Slow Query 확인 → 쿼리 최적화 목록 작성
- Connection Pool 설정 → RDS Proxy 도입 검토
애플리케이션
- Peak CPU/Memory → Lambda 메모리 할당 (권고: 1024~3008MB)
- Peak RPS → Lambda 동시 실행 제한 설정
- Session/State 관리 → DynamoDB/ElastiCache 마이그레이션
인프라
- API Gateway 스로틀링 설정
- CloudWatch 로그 및 X-Ray 추적 설정
- S3 + CloudFront (정적 자산)
- Secrets Manager (환경 변수)
🔍 문제 해결
| 증상 | 해결방법 |
|---|---|
Permission denied |
chmod +x chocomae-24h-monitoring.sh |
| MariaDB 접근 실패 | sudo visudo에서 NOPASSWD 설정 |
iostat: command not found |
sudo apt-get install -y sysstat |
Apache /server-status 오류 |
sudo a2enmod status && sudo systemctl restart apache2 |
| 로그 파일 없음 | mkdir -p /home/ubuntu/chocomae-monitoring |
📋 수집되는 지표 (전체)
Apache (WEB)
- cpu, mem, busy_workers, idle_workers, ka_connections, total_accesses
PHP-FPM (WAS)
- cpu, mem, process_count
MariaDB (DB)
- cpu, mem, connections, max_connections, threads_running, slow_queries
시스템
- cpu_usage, mem_usage, mem_free, disk_usage, disk_free, disk_io_read, disk_io_write
📚 상세 가이드
더 자세한 내용은 다음 문서를 참조하세요:
- README.md - 전체 개요 및 분석 가이드
- MONITORING_SETUP.md - 설치, 설정, 문제 해결
- chocomae-24h-monitoring.sh - 스크립트 코드 및 주석
- analyze_monitoring.py - 분석 스크립트 코드 및 함수 설명
💡 팁
1. 모니터링 주기 조정
# 스크립트 내 INTERVAL 변수 수정
# INTERVAL=60 (기본값, 1분)
# INTERVAL=30 (더 자세한 데이터, 저장 용량 2배)
2. 특정 시간대만 분석
import pandas as pd
df = pd.read_csv('all_data.csv')
df['timestamp'] = pd.to_datetime(df['timestamp'])
# 평일 오후 1~3시만 분석
peak = df[
(df['timestamp'].dt.hour >= 13) &
(df['timestamp'].dt.hour < 15) &
(df['timestamp'].dt.weekday < 5) # 월~금
]
print(peak['system_cpu_usage_percent'].describe())
3. 특정 이슈 추적
# Slow Query 급증 확인
grep "mariadb_slow_queries" /home/ubuntu/chocomae-monitoring/chocomae-*.log | tail -50
# 메모리 스파이크 확인
grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}" /home/ubuntu/chocomae-monitoring/chocomae-*.log | \
awk -F',' '$10 > 90 {print $0}'
✅ 완료 체크리스트
- 필수 패키지 설치 완료
- sudo NOPASSWD 설정 완료
- 스크립트 배포 및 권한 설정 완료
- 모니터링 시작 확인 (로그 파일 생성)
- 1주일 후 데이터 수집 완료
- Python 분석 스크립트 실행
- Serverless 마이그레이션 체크리스트 작성
- AWS 인프라 설계 시작
📞 피드백 및 커스터마이징
스크립트 커스터마이징이 필요하면:
- 모니터링 주기 조정:
INTERVAL변수 수정 - 추가 지표 수집:
get_*_metrics()함수 확장 - 데이터 보관 기간:
LOG_RETENTION_DAYS수정
분석 스크립트 커스터마이징이 필요하면:
analyze_monitoring.py의 함수 추가/수정- 자체 분석 로직 구현 (pandas 기반)
시작하기: ssh ubuntu@<instance> → ./chocomae-24h-monitoring.sh &
1주일 후: python3 analyze_monitoring.py /home/ubuntu/chocomae-monitoring
이 가이드를 완료하는 데 약 10-15분이 소요됩니다.