CloudWatch Contributor Insights for DynamoDB 入门 - Amazon DynamoDB

CloudWatch Contributor Insights for DynamoDB 入门

本节介绍如何使用 Amazon DynamoDB 控制台或 AWS Command Line Interface(AWS CLI),以不同模式启用和使用 Amazon CloudWatch Contributor Insights 来满足您的监控需求。

在以下示例中,您将使用 DynamoDB 入门教程中定义的 DynamoDB 表。

选择 Contributor Insights 模式

在启用 Contributor Insights 之前,您应该对可用的两种模式有所了解。查看模式对比,选择与您的具体需求更相符的选项。

方面 访问的键和受限的键模式 受限的键模式
监控 所有请求(成功且受限制) 仅受限的请求
图表 最常访问的项目 + 最受限的项目 仅最受限的项目
适用于 针对性的分析和优化 节流监控
使用场景 您需要全面监测访问模式。您在进行短期分析或调试。 您最关心的是识别和解决节流问题。您想保持启用 Contributor Insights 来获取实时节流警报。

使用 Contributor Insights(控制台)

控制台提供了直观的方法来启用 Contributor Insights,而且您可以根据监控需求选择相应的模式。

在控制台中使用 Contributor Insights
  1. 登录 AWS Management Console,并打开 DynamoDB 控制台:https://console.aws.amazon.com/dynamodb/

  2. 在控制台左侧的导航窗格中,选择

  3. 选择 Music 表。

  4. 选择监控选项卡。

  5. 选择开启 CloudWatch Contributor Insights

    显示监控选项卡和按钮的控制台屏幕截图。
  6. 管理 CloudWatch Contributor Insights 设置对话框中,为 Music 基表和 AlbumTitle-index 全局二级索引切换到开启

  7. 对于这两者,将仅限受限的键模式开关保留在关闭位置,然后选择保存更改

    显示 Contributor Insights 状态列表选项的控制台屏幕截图。

    这会为表和 GSI 均启用默认的访问的键和受限的键模式,从而监控访问的项目和受限的项目。将仅限受限的键模式开关切换到启用受限的键模式的位置。

    如果操作失败,请参阅 Amazon DynamoDB API 参考中的 DescribeContributorInsights FailureException 了解可能的原因。

  8. 现在,对于 Music 表,可在监控选项卡上查看 CloudWatch Contributor Insights 图表。由于您启用了访问的键和受限的键模式,因此您可以看到访问的项目和受限的项目的图表。

    显示 Contributor Insights 选项卡和 music 表多个图表的控制台屏幕截图。

切换模式

您可以随时切换模式,而无需禁用 Contributor Insights。

切换 Contributor Insights 模式
  1. 在表的监控选项卡上,选择管理 CloudWatch Contributor Insights

  2. 管理 Contributor Insights 设置对话框中,对于每个基表或 GSI:

    • 开启或关闭仅受限的键模式,来启用受限的键模式或者返回默认的访问的键和受限的键模式。

    • 开启开关关闭,对表或 GSI 禁用 CloudWatch Contributor Insight。

  3. 选择保存更改

    完成后,图表将反映新模式。

创建 CloudWatch 告警

按照以下步骤创建 CloudWatch 警报,并在任何分区键使用了超过 5 万个 ConsumedThroughputUnits 或出现节流时收到通知。

  1. 登录 AWS Management Console,并打开 CloudWatch 控制台:https://console.aws.amazon.com/cloudwatch/

  2. 在控制台左侧的导航窗格中,选择 Contributor Insights

  3. 根据您的模式和要监控的对象,选择相应的规则:

    • 要监控访问的项目(仅适用于访问的键和受限的键模式):选择 DynamoDBContributorInsights-PKC-Music

    • 要监控受限的项目(两种模式):选择 DynamoDBContributorInsights-PKT-Music

  4. 选择操作下拉菜单。

  5. 选择在指标中查看

  6. 选择最大贡献者值

    注意

    Max Contributor ValueMaximum 返回有用的统计信息。此列表中的其他统计信息不返回有意义的值。

    显示 Contributor Insights 选项卡和按钮的控制台屏幕截图。
  7. 操作列选择创建告警

    显示 Contributor Insights 状态列表选项的控制台屏幕截图。
  8. 输入适当的阈值,然后选择下一步

    • 对于访问的项目(PKC 规则):为 ConsumedThroughputUnits 输入 50000

    • 对于受限的项目(PKT 规则):为 ThrottleCount 输入 1,这样就能在出现任何节流情况时收到警报

    显示 Contributor Insights 选项卡和按钮的控制台屏幕截图。
  9. 有关如何为警报配置通知的详细信息,请参阅使用 Amazon CloudWatch 警报

使用 Contributor Insights (AWS CLI)

AWS CLI 提供对 Contributor Insights 的程序化访问,同时完全支持这两种模式。您可以在启用 Contributor Insights 时指定模式,也可以在以后切换模式。

默认模式下的基本操作

使用 Contributor Insights 的默认设置
  1. Music 基表上启用 CloudWatch Contributor Insights for DynamoDB,并使用访问的键和受限的键模式。由于 ACCESSED_AND_THROTTLED_KEYS 是默认模式,因此可以省略 --contributor-insights-mode=ACCESSED_AND_THROTTLED_KEYS 参数。

    aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE
  2. AlbumTitle-index 全局二级索引启用 Contributor Insights for DynamoDB。

    aws dynamodb update-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index \ --contributor-insights-action=ENABLE
  3. 获取 Music 表及其所有索引的状态与规则。

    aws dynamodb describe-contributor-insights --table-name Music

    响应将包括 ContributorInsightsMode 字段,显示 ACCESSED_AND_THROTTLED_KEYS

  4. 列出 Music 表及其所有索引的状态。

    aws dynamodb list-contributor-insights --table-name Music

启用受限的键模式

以受限的键模式启用 Contributor Insights
  1. Music 基表上启用 CloudWatch Contributor Insights for DynamoDB,并使用受限的键模式。

    aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS
  2. AlbumTitle-index 全局二级索引启用 Contributor Insights 并使用受限的键模式。

    aws dynamodb update-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS
  3. 说明 Contributor Insights 配置来验证模式。

    aws dynamodb describe-contributor-insights --table-name Music

    与默认模式相比,响应显示的 ContributorInsightsModeTHROTTLED_KEYS,且规则更少。

切换模式

切换 Contributor Insights 模式
  1. 受限的键模式切换到访问的键和受限的键模式。

    aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=ACCESSED_AND_THROTTLED_KEYS
  2. 访问的键和受限的键模式切换到受限的键模式。

    aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS
  3. 检查切换期间的状态。

    aws dynamodb describe-contributor-insights --table-name Music

    在模式切换期间,ContributorInsightsStatus 将显示为 ENABLING。完成后,对于新的模式将显示 ENABLED

管理 Contributor Insights

管理 Contributor Insights 设置
  1. AlbumTitle-index 全局二级索引禁用 CloudWatch Contributor Insights for DynamoDB。

    aws dynamodb update-contributor-insights \ --table-name Music --index-name AlbumTitle-index \ --contributor-insights-action=DISABLE
  2. 列出您的账户中的所有 Contributor Insights 配置。

    aws dynamodb list-contributor-insights

    这将显示所有启用了 Contributor Insights 的表和索引,以及所用的模式。

  3. 获取有关特定配置的详细信息。

    aws dynamodb describe-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index

响应示例

以下响应示例显示了各模式之间的不同:

访问的键和受限的键模式响应

{ "TableName": "Music", "ContributorInsightsRuleList": [ "DynamoDBContributorInsights-PKC-Music-1234567890123", "DynamoDBContributorInsights-PKT-Music-1234567890123", "DynamoDBContributorInsights-SKC-Music-1234567890123", "DynamoDBContributorInsights-SKT-Music-1234567890123" ], "ContributorInsightsStatus": "ENABLED", "ContributorInsightsMode": "ACCESSED_AND_THROTTLED_KEYS", "LastUpdateDateTime": "2024-01-15T10:30:00.000Z" }

受限的键模式响应

{ "TableName": "Music", "ContributorInsightsRuleList": [ "DynamoDBContributorInsights-PKT-Music-1234567890123", "DynamoDBContributorInsights-SKT-Music-1234567890123" ], "ContributorInsightsStatus": "ENABLED", "ContributorInsightsMode": "THROTTLED_KEYS", "LastUpdateDateTime": "2024-01-15T10:35:00.000Z" }

请注意,受限的键模式的规则较少(只有 PKT 和 SKT),这与更有侧重点的监控相对应。