Skip to content

Commit f2f5b67

Browse files
author
Eugene Cheung
authored
fix(dynamo): divide GSI consumed RCU/WCU metrics by period (#368)
Fixes #362 Results in a dashboard widget with a source like: ``` { "view": "timeSeries", "title": "Read Capacity", "region": "us-east-1", "metrics": [ [ { "label": "Consumed", "expression": "consumed_rcu_sum/PERIOD(consumed_rcu_sum)", "region": "us-east-1" } ], [ "AWS/DynamoDB", "ConsumedReadCapacityUnits", "GlobalSecondaryIndexName", "SampleTable2-GSI", "TableName", "SampleTable2", { "stat": "Sum", "visible": false, "id": "consumed_rcu_sum", "region": "us-east-1" } ], [ ".", "ProvisionedReadCapacityUnits", ".", ".", ".", ".", { "label": "Provisioned", "stat": "Sum", "region": "us-east-1" } ] ], "yAxis": { "left": { "min": 0, "label": "Count", "showUnits": false } }, "timezone": "UTC" } ``` --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 005d951 commit f2f5b67

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

lib/monitoring/aws-dynamo/DynamoTableGlobalSecondaryIndexMetricFactory.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export interface DynamoTableGlobalSecondaryIndexMetricFactoryProps {
1212

1313
export class DynamoTableGlobalSecondaryIndexMetricFactory {
1414
protected readonly metricFactory: MetricFactory;
15+
protected readonly table: ITable;
1516
protected readonly dimensionsMap: DimensionsMap;
1617

1718
constructor(
1819
metricFactory: MetricFactory,
1920
props: DynamoTableGlobalSecondaryIndexMetricFactoryProps
2021
) {
2122
this.metricFactory = metricFactory;
23+
this.table = props.table;
2224
this.dimensionsMap = {
2325
TableName: props.table.tableName,
2426
GlobalSecondaryIndexName: props.globalSecondaryIndexName,
@@ -48,24 +50,28 @@ export class DynamoTableGlobalSecondaryIndexMetricFactory {
4850
}
4951

5052
metricConsumedReadCapacityUnits() {
51-
return this.metricFactory.createMetric(
52-
"ConsumedReadCapacityUnits",
53-
MetricStatistic.SUM,
54-
"Consumed",
55-
this.dimensionsMap,
56-
undefined,
57-
DynamoDbNamespace
53+
return this.metricFactory.createMetricMath(
54+
"consumed_rcu_sum/PERIOD(consumed_rcu_sum)",
55+
{
56+
consumed_rcu_sum: this.table.metricConsumedReadCapacityUnits({
57+
statistic: MetricStatistic.SUM,
58+
dimensionsMap: this.dimensionsMap,
59+
}),
60+
},
61+
"Consumed"
5862
);
5963
}
6064

6165
metricConsumedWriteCapacityUnits() {
62-
return this.metricFactory.createMetric(
63-
"ConsumedWriteCapacityUnits",
64-
MetricStatistic.SUM,
65-
"Consumed",
66-
this.dimensionsMap,
67-
undefined,
68-
DynamoDbNamespace
66+
return this.metricFactory.createMetricMath(
67+
"consumed_wcu_sum/PERIOD(consumed_wcu_sum)",
68+
{
69+
consumed_wcu_sum: this.table.metricConsumedWriteCapacityUnits({
70+
statistic: MetricStatistic.SUM,
71+
dimensionsMap: this.dimensionsMap,
72+
}),
73+
},
74+
"Consumed"
6975
);
7076
}
7177

test/monitoring/aws-dynamo/__snapshots__/DynamoTableGlobalSecondaryIndexMonitoring.test.ts.snap

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)