创建 CloudWatch 警报以监控 DynamoDB
可以创建 CloudWatch 告警,在告警改变状态时发送 Amazon SNS 消息。警报会每隔一段时间 (由您指定) 监控一个指标,并根据相对于给定阈值的指标值每隔若干个时间段执行一项或多项操作。操作是一个发送到 Amazon SNS 主题或 Auto Scaling 策略的通知。警报只会调用操作进行持续的状态变更。CloudWatch 告警不调用操作,因为这些操作处于特定状态;状态必须改变并保持指定时间。
创建 CloudWatch 告警时必须指定所有需要的维度,因为 CloudWatch 不会为缺少的维度聚合指标。创建告警时,对缺少的维度创建 CloudWatch 告警不会导致错误。
有关 DynamoDB 中受支持的指标及其所需维度的列表,请参阅 查看 指标和维度。
如何在占用整个读取容量之前收到通知?
-
创建 Amazon SNS 主题,
arn:aws:sns:us-east-1:123456789012:capacity-alarm
。有关更多信息,请参阅设置 Amazon Simple Notification Service。
-
创建告警。在此示例中,我们假设预置容量为五个读取容量单位。
aws cloudwatch put-metric-alarm \ --alarm-name ReadCapacityUnitsLimitAlarm \ --alarm-description "Alarm when read capacity reaches 80% of my provisioned read capacity" \ --namespace AWS/DynamoDB \ --metric-name ConsumedReadCapacityUnits \ --dimensions Name=TableName,Value=myTable \ --statistic Sum \ --threshold 240 \ --comparison-operator GreaterThanOrEqualToThreshold \ --period 60 \ --evaluation-periods 1 \ --alarm-actions arn:aws:sns:us-east-1:123456789012:capacity-alarm
-
测试告警。
aws cloudwatch set-alarm-state --alarm-name ReadCapacityUnitsLimitAlarm --state-reason "initializing" --state-value OK
aws cloudwatch set-alarm-state --alarm-name ReadCapacityUnitsLimitAlarm --state-reason "initializing" --state-value ALARM
如果 1 分钟(60 秒)内占用的读取容量为每秒至少 4 个单位(预置读取容量的 80% 为 5),将激活告警。因此 threshold
为 240 个读取容量单位(4 个单位/秒 * 60 秒)。更新读取容量后,应相应更新告警计算。可以通过 DynamoDB 控制台创建告警来避免此过程。这样将自动更新告警。
如何知道是否有任何请求超出表的预置吞吐量配额?
-
创建 Amazon SNS 主题,
arn:aws:sns:us-east-1:123456789012:requests-exceeding-throughput
。有关更多信息,请参阅设置 Amazon Simple Notification Service。
-
创建告警。
aws cloudwatch put-metric-alarm \ --alarm-name RequestsExceedingThroughputAlarm\ --alarm-description "Alarm when my requests are exceeding provisioned throughput quotas of a table" \ --namespace AWS/DynamoDB \ --metric-name ThrottledRequests \ --dimensions Name=TableName,Value=myTable Name=Operation,Value=aDynamoDBOperation \ --statistic Sum \ --threshold 0 \ --comparison-operator GreaterThanThreshold \ --period 300 \ --unit Count \ --evaluation-periods 1 \ --alarm-actions arn:aws:sns:us-east-1:123456789012:requests-exceeding-throughput
-
测试告警。
aws cloudwatch set-alarm-state --alarm-name RequestsExceedingThroughputAlarm --state-reason "initializing" --state-value OK
aws cloudwatch set-alarm-state --alarm-name RequestsExceedingThroughputAlarm --state-reason "initializing" --state-value ALARM
如何确定是否发生任何系统错误?
-
创建 Amazon SNS 主题,
arn:aws:sns:us-east-1:123456789012:notify-on-system-errors
。有关更多信息,请参阅设置 Amazon Simple Notification Service。
-
创建告警。
aws cloudwatch put-metric-alarm \ --alarm-name SystemErrorsAlarm \ --alarm-description "Alarm when system errors occur" \ --namespace AWS/DynamoDB \ --metric-name SystemErrors \ --dimensions Name=TableName,Value=myTable Name=Operation,Value=aDynamoDBOperation \ --statistic Sum \ --threshold 0 \ --comparison-operator GreaterThanThreshold \ --period 60 \ --unit Count \ --evaluation-periods 1 \ --alarm-actions arn:aws:sns:us-east-1:123456789012:notify-on-system-errors
-
测试告警。
aws cloudwatch set-alarm-state --alarm-name SystemErrorsAlarm --state-reason "initializing" --state-value OK
aws cloudwatch set-alarm-state --alarm-name SystemErrorsAlarm --state-reason "initializing" --state-value ALARM