일일 EstimatedCharges를 모니터링하고 사용량 임계값에 따라 CloudWatch 경보를 트리거하려면 어떻게 해야 합니까?
일일 EstimatedCharges를 모니터링하고 사용량 임계값에 따라 Amazon CloudWatch 경보를 트리거하려면 어떻게 해야 합니까?
간략한 설명
EstimatedCharges 지표는 약 6시간 간격을 두고 게시됩니다. 결과는 매월 다시 설정됩니다. MetricMath RATE 표현식은 최신 데이터 포인트 값과 이전 데이터 포인트 값의 차이를 두 값 사이의 시간(초)으로 나누어서 계산합니다. 이 표현식을 사용해서 각 날짜의 EstimatedCharges 값을 계산할 수 있습니다.
해결 방법
참고: AWS Command Line Interface(AWS CLI) 명령을 실행할 때 오류가 발생하는 경우 AWS CLI의 가장 최신 버전을 사용하고 있는지 확인하세요.
RATE 표현식을 테스트하고 결과 확인
CloudWatch 경보를 생성하기 전에 GetMetricData API를 호출하여 RATE 표현식 테스트합니다.
$ cat metric_data_queries.json { "MetricDataQueries": [ { "Id": "m1", "MetricStat": { "Metric": { "Namespace": "AWS/Billing", "MetricName": "EstimatedCharges", "Dimensions": [ { "Name": "Currency", "Value": "USD" } ] }, "Period": 86400, "Stat": "Maximum" } }, { "Id": "e1", "Expression": "IF(RATE(m1)>0,RATE(m1)*86400,0)", "Label": "DailyEstimatedCharges", "Period": 86400 } ], "StartTime": "2020-06-01T00:00:00Z", "EndTime": "2020-06-05T00:00:00Z", "ScanBy": "TimestampAscending" } $ aws cloudwatch get-metric-data --cli-input-json file://metric_data_queries.json { "MetricDataResults": [ { "Id": "m1", "Label": "EstimatedCharges", "Timestamps": [ "2020-06-01T00:00:00Z", "2020-06-02T00:00:00Z", "2020-06-03T00:00:00Z", "2020-06-04T00:00:00Z" ], "Values": [ 0.0, 22.65, 34.74, 46.91 ], "StatusCode": "Complete" }, { "Id": "e1", "Label": "DailyEstimatedCharges", "Timestamps": [ "2020-06-02T00:00:00Z", "2020-06-03T00:00:00Z", "2020-06-04T00:00:00Z" ], "Values": [ 22.65, 12.090000000000003, 12.169999999999995 ], "StatusCode": "Complete" } ], "Messages": [] }
출력 테이블:
타임스탬프 | 2020-06-01T00:00:00Z | 2020-06-02T00:00:00Z | 2020-06-03T00:00:00Z | 2020-06-04T00:00:00Z |
EstimatedCharges | 0.0 | 22.65 | 34.74 | 46.91 |
DailyEstimatedCharges | --- | 22.65 | 12.09 | 12.17 |
출력 테이블에서 DailyEstimatedCharges가 최신 데이터 포인트와 이전 데이터 포인트 사이의 차이만큼 올바르게 계산되었는지 확인합니다. 이 표현식을 사용하여 CloudWatch 경보를 생성합니다.
AWS Management Console을 사용하여 CloudWatch 경보 생성
1. 지표 수식 표현식을 사용한 CloudWatch 경보 생성 단계를 따릅니다.
2. CloudWatch 지표 페이지의 [소스(Source)] 탭에 다음 코드를 붙여넣습니다. 이 코드는 EstimatedCharges를 레이블이 "m1"인 기본 지표로 사용하여 지표 수학 표현식 **[ IF(RATE(m1)>0,RATE(m1)*86400,0) ]**을 생성합니다.
{ "metrics": [ [ { "expression": "IF(RATE(m1)>0,RATE(m1)*86400,0)", "label": "Expression1", "id": "e1", "period": 86400, "stat": "Maximum" } ], [ "AWS/Billing", "EstimatedCharges", "Currency", "USD", { "id": "m1" } ] ], "view": "timeSeries", "stacked": false, "region": "us-east-1", "stat": "Maximum", "period": 86400 }
3. MetricMath 표현식에 대한 CloudWatch 경보를 생성합니다. 이렇게 하려면 [그래프로 표시된 지표(Graphed metric)]를 선택합니다. DailyEstimatedCharges 지표의 [작업(Actions)] 열에서 [경보(Alarm)] 아이콘을 선택합니다.
4. CloudWatch 경보 생성 마법사에서: 지표 구성의 세부 정보를 확인합니다. 적절한 임계값을 추가하여 임계값을 초과하면 알림을 수신하도록 합니다(예: 50 USD). 경보 작업을 구성합니다. 경보 이름과 설명을 추가합니다.
AWS CLI를 사용하여 CloudWatch 경보 생성
1. 경보 구성을 JSON 파일로 생성합니다.
$ cat alarm_config.json { "AlarmName": "DailyEstimatedCharges", "AlarmDescription": "This alarm would be triggered if the daily estimated charges exceeds 50$", "ActionsEnabled": true, "AlarmActions": [ "arn:aws:sns:<REGION>:<ACCOUNT_ID>:<SNS_TOPIC_NAME>" ], "EvaluationPeriods": 1, "DatapointsToAlarm": 1, "Threshold": 50, "ComparisonOperator": "GreaterThanOrEqualToThreshold", "TreatMissingData": "breaching", "Metrics": [{ "Id": "m1", "MetricStat": { "Metric": { "Namespace": "AWS/Billing", "MetricName": "EstimatedCharges", "Dimensions": [{ "Name": "Currency", "Value": "USD" }] }, "Period": 86400, "Stat": "Maximum" }, "ReturnData": false }, { "Id": "e1", "Expression": "IF(RATE(m1)>0,RATE(m1)*86400,0)", "Label": "DailyEstimatedCharges", "ReturnData": true }] }
참고: REGION, ACCOUNT_ID 및 SNS_TOPIC_NAME을 해당 값으로 업데이트해야 합니다.
2. PutMetricAlarm API를 호출합니다.
aws cloudwatch put-metric-alarm --cli-input-json file://alarm_config.json
(선택 사항) 최대 DailyEstimatedCharges 값에서 가장 비중이 높았던 전날의 상위 10개 기여 요소 찾기
다음의 쿼리를 사용합니다.
$ cat top_contributors_query.json { "MetricDataQueries": [{ "Id": "e1", "Expression": "SORT(RATE(SEARCH('{AWS/Billing,Currency,ServiceName} AWS/Billing ServiceName', 'Maximum', 86400))*86400, MAX, DESC, 10)", "Label": "DailyEstimatedCharges", "Period": 86400 }], "ScanBy": "TimestampAscending" } $ aws cloudwatch get-metric-data --cli-input-json file://top_contributors_query.json --start-time `date -v -2d '+%Y-%m-%dT%H:%M:%SZ'` --end-time `date '+%Y-%m-%dT%H:%M:%SZ'` --region us-east-1
참고: StartTime 및 EndTime에 지원되는 DateTime 형식은 '2020-01-01T00:00:00Z'입니다.
중요: 앞의 명령은 각 GetMetricData API 호출로 검색된 지표 수를 기준으로 요금이 발생합니다. 자세한 내용은 Amazon CloudWatch 요금을 참조하세요.

관련 콘텐츠
- 질문됨 4달 전lg...
- 질문됨 2달 전lg...
- 질문됨 6년 전lg...
- 질문됨 3달 전lg...
- AWS 공식업데이트됨 일 년 전
- AWS 공식업데이트됨 5달 전
- AWS 공식업데이트됨 일 년 전
- AWS 공식업데이트됨 7달 전