为 cdk-monitoring-constructs 中的指标指定 AWS 区域

问题描述 投票:0回答:1

我有 3 个 dyanmodb 表,每个表位于不同的 AWS 区域。我想使用 cdk-monitoring-constructs 来监视它们,并在同一仪表板上为每个 dyanmodb 表提供指标。我创建监控外观,然后像这样迭代我的区域:

for (const region of regionsToMonitor) {

 const dyanmodbToMonitor = tableMap.get(region)
 monitoring.monitorDynamoTable(
     {
          table: dyanmodbToMonitor
      }
  )

但是,这仅适用于我在 us-east-1 中创建的表。另外两个表(一个位于 EU,另一个位于 us-west-2)在生成的仪表板中缺少指标。我可以在这两个表的 cloudwatch 指标源中看到它们是空的,因为它们使用了错误的区域(即使用 us-east-1 而不是 us-west-2):

{
    "view": "timeSeries",
    "title": "Latency (Average)",
    "region": "us-east-1",

当我手动更改其定义中的区域时,就会出现指标。

如何指定将这些表添加到受监控时应使用哪个区域?

amazon-web-services amazon-cloudwatch aws-cdk
1个回答
0
投票

TL;博士

不幸的是,您无法通过 cdk-monitoring-constructs 使用来自另一个区域的指标创建图表。当前的实现不支持它。


我发现这个问题很有趣,所以我跟踪了代码并意识到当前的实现并没有将

region
传递给
GraphWidget

这里是代码行显示了aws-cdk如何定义

GraphWidget
的道具。

export interface MetricWidgetProps {
  ...
  /**
   * The region the metrics of this graph should be taken from
   *
   * @default Current region
   */
  readonly region?: string;
  ...
}

这里是代码行显示了 cdk-monitoring-constructs 如何生成图表。

return new GraphWidget({
  width,
  height,
  title: "Read Usage",
  left: [this.consumedReadUnitsMetric, this.provisionedReadUnitsMetric],
  leftYAxis: CountAxisFromZero,
  leftAnnotations: this.dynamoReadCapacityAnnotations,
  right: [this.readCapacityUsageMetric],
  rightYAxis: PercentageAxisFromZeroToHundred,
  legendPosition: LegendPosition.RIGHT,
});

如您所见,它不会将

region
参数传递给
GraphWidget
,这导致图表始终使用当前区域(CloudFormation Stack 区域)中的指标创建。

© www.soinside.com 2019 - 2024. All rights reserved.