"""데이터 모델 정의
EBS CloudWatch 지표 계산에 사용되는 데이터클래스들을 정의합니다.
Requirements:
- 2.2: IOPS 평균, 최대, 최소 값 계산
- 3.2: 처리량 계산
- 4.2: 스냅샷 크기 조회
- 7.1-7.9: 고급 지표 계산
"""
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
@dataclass
class MetricDataPoint:
"""CloudWatch 지표의 단일 데이터 포인트
Attributes:
timestamp: 데이터 포인트의 타임스탬프
value: 지표 값
unit: 지표 단위 (예: Count, Bytes, Seconds)
"""
timestamp: datetime
value: float
unit: str
@dataclass
class MetricResult:
"""CloudWatch 지표 조회 결과
Attributes:
metric_name: CloudWatch 지표 이름
volume_id: EBS 볼륨 ID
datapoints: 데이터 포인트 목록
average: 평균값 (선택적)
maximum: 최대값 (선택적)
minimum: 최소값 (선택적)
sum: 합계 (선택적)
Requirements: 2.2, 3.2
"""
metric_name: str
volume_id: str
datapoints: list[MetricDataPoint]
average: Optional[float] = None
maximum: Optional[float] = None
minimum: Optional[float] = None
sum: Optional[float] = None
@dataclass
class IOPSResult:
"""IOPS 계산 결과
Attributes:
volume_id: EBS 볼륨 ID
start_time: 조회 시작 시간
end_time: 조회 종료 시간
read_iops: 읽기 IOPS 지표 결과
write_iops: 쓰기 IOPS 지표 결과
total_avg_iops: 총 평균 IOPS (읽기 + 쓰기)
total_max_iops: 총 최대 IOPS (읽기 + 쓰기)
Requirements: 2.2
"""
volume_id: str
start_time: datetime
end_time: datetime
read_iops: MetricResult
write_iops: MetricResult
total_avg_iops: float
total_max_iops: float
@dataclass
class ThroughputResult:
"""처리량 계산 결과
Attributes:
volume_id: EBS 볼륨 ID
start_time: 조회 시작 시간
end_time: 조회 종료 시간
read_throughput: 읽기 처리량 지표 결과 (bytes/sec)
write_throughput: 쓰기 처리량 지표 결과 (bytes/sec)
read_throughput_mb_s: 읽기 처리량 (MB/s)
write_throughput_mb_s: 쓰기 처리량 (MB/s)
total_throughput_mb_s: 총 처리량 (MB/s)
Requirements: 3.2
"""
volume_id: str
start_time: datetime
end_time: datetime
read_throughput: MetricResult # bytes/sec
write_throughput: MetricResult # bytes/sec
read_throughput_mb_s: float
write_throughput_mb_s: float
total_throughput_mb_s: float
@dataclass
class SnapshotInfo:
"""EBS 스냅샷 정보
Attributes:
snapshot_id: 스냅샷 ID
volume_id: 원본 볼륨 ID
size_gb: 스냅샷 크기 (GB)
start_time: 스냅샷 생성 시작 시간
state: 스냅샷 상태 (pending, completed, error)
description: 스냅샷 설명 (선택적)
Requirements: 4.2
"""
snapshot_id: str
volume_id: str
size_gb: int
start_time: datetime
state: str
description: Optional[str] = None
@dataclass
class AdvancedMetricsResult:
"""고급 지표 계산 결과
CloudWatch 지표를 조합하여 계산한 고급 성능 지표들을 포함합니다.
Attributes:
volume_id: EBS 볼륨 ID
start_time: 조회 시작 시간
end_time: 조회 종료 시간
period: 지표 수집 간격 (초)
io_use_percent: I/O 사용률 (%)
계산식: 100 - ((VolumeIdleTime / Period) * 100)
avg_read_latency_ms: 평균 읽기 지연 시간 (ms)
계산식: (VolumeTotalReadTime / VolumeReadOps) * 1000
avg_write_latency_ms: 평균 쓰기 지연 시간 (ms)
계산식: (VolumeTotalWriteTime / VolumeWriteOps) * 1000
read_io_size_kib: 읽기 I/O 크기 (KiB)
계산식: (VolumeReadBytes / VolumeReadOps) / 1024
write_io_size_kib: 쓰기 I/O 크기 (KiB)
계산식: (VolumeWriteBytes / VolumeWriteOps) / 1024
avg_read_iops: 평균 읽기 IOPS
계산식: VolumeReadOps / Period
avg_write_iops: 평균 쓰기 IOPS
계산식: VolumeWriteOps / Period
avg_total_iops: 평균 총 IOPS
계산식: avg_read_iops + avg_write_iops
avg_read_throughput_mib_s: 평균 읽기 처리량 (MiB/s)
계산식: (VolumeReadBytes / Period) / 1024^2
avg_write_throughput_mib_s: 평균 쓰기 처리량 (MiB/s)
계산식: (VolumeWriteBytes / Period) / 1024^2
avg_total_throughput_mib_s: 평균 총 처리량 (MiB/s)
계산식: avg_read_throughput_mib_s + avg_write_throughput_mib_s
bursting_read_iops: 버스팅 읽기 IOPS
계산식: VolumeReadOps / (Period - VolumeIdleTime)
bursting_write_iops: 버스팅 쓰기 IOPS
계산식: VolumeWriteOps / (Period - VolumeIdleTime)
bursting_total_iops: 버스팅 총 IOPS
계산식: bursting_read_iops + bursting_write_iops
bursting_read_throughput_mib_s: 버스팅 읽기 처리량 (MiB/s)
계산식: (VolumeReadBytes / (Period - VolumeIdleTime)) / 1024^2
bursting_write_throughput_mib_s: 버스팅 쓰기 처리량 (MiB/s)
계산식: (VolumeWriteBytes / (Period - VolumeIdleTime)) / 1024^2
bursting_total_throughput_mib_s: 버스팅 총 처리량 (MiB/s)
계산식: bursting_read_throughput_mib_s + bursting_write_throughput_mib_s
burst_balance: BurstBalance 값 (선택적)
gp2 볼륨의 버스트 크레딧 잔액 (%)
Requirements: 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9
"""
volume_id: str
start_time: datetime
end_time: datetime
period: int
# I/O 사용률 (Requirements: 7.1)
io_use_percent: float
# 지연 시간 (ms) (Requirements: 7.2, 7.3)
avg_read_latency_ms: float
avg_write_latency_ms: float
# I/O 크기 (KiB) (Requirements: 7.4, 7.5)
read_io_size_kib: float
write_io_size_kib: float
# 평균 IOPS (Requirements: 7.6)
avg_read_iops: float
avg_write_iops: float
avg_total_iops: float
# 평균 처리량 (MiB/s) (Requirements: 7.7)
avg_read_throughput_mib_s: float
avg_write_throughput_mib_s: float
avg_total_throughput_mib_s: float
# 버스팅 IOPS (Requirements: 7.8)
bursting_read_iops: float
bursting_write_iops: float
bursting_total_iops: float
# 버스팅 처리량 (MiB/s) (Requirements: 7.9)
bursting_read_throughput_mib_s: float
bursting_write_throughput_mib_s: float
bursting_total_throughput_mib_s: float
# BurstBalance (선택적)
burst_balance: Optional[float] = None