AWS CloudWatch는 AWS 리소스와 애플리케이션을 위한 통합 모니터링·관찰 가능성 서비스다. 메트릭 수집, 로그 집계, 경보 설정, 대시보드, 이상 탐지를 하나의 서비스로 제공한다.
핵심 구성 요소
Metrics: 시계열 성능 데이터 (CPU, 메모리 등)
Logs: 애플리케이션/시스템 로그
Alarms: 임계치 초과 시 SNS/Auto Scaling 트리거
Dashboards: 통합 모니터링 화면
Container Insights: EKS/ECS 컨테이너 모니터링
커스텀 메트릭
python
import boto3
cloudwatch = boto3.client('cloudwatch', region_name='ap-northeast-2')
# 커스텀 메트릭 발행
cloudwatch.put_metric_data(
Namespace='MyApp/Business',
MetricData=[
{
'MetricName': 'OrdersPerMinute',
'Value': 42.0,
'Unit': 'Count',
'Dimensions': [
{'Name': 'Service', 'Value': 'OrderService'},
{'Name': 'Environment', 'Value': 'production'},
]
}
]
)
Alarm 설정
bash
# API 에러율 알람 (AWS CLI)
aws cloudwatch put-metric-alarm --alarm-name "HighAPIErrorRate" --metric-name "5XXError" --namespace "AWS/ApiGateway" --statistic Sum --period 60 --threshold 10 --comparison-operator GreaterThanThreshold --evaluation-periods 2 --alarm-actions "arn:aws:sns:ap-northeast-2:123:alerts"
Logs Insights 쿼리
fields @timestamp, @message
| filter @message like /ERROR/
| stats count(*) as errorCount by bin(5m)
| sort @timestamp desc
관련 개념