Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit dc81ee3

Browse files
committed
Change the way to read the consumed capacity
- Now uses the sum and then divides it by the period which gives us an accurate consumed capacity
1 parent 1febbb7 commit dc81ee3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/CapacityCalculator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class CapacityCalculator extends CapacityCalculatorBase {
3030
// Default algorithm for projecting a good value for the current ConsumedThroughput is:
3131
// 1. Query 5 average readings each spanning a minute
3232
// 2. Select the Max value from those 5 readings
33-
let averages = data.Datapoints.map(dp => dp.Average);
33+
let averages = data.Datapoints.map(dp => dp.Sum / data.period);
3434
return Math.max(...averages);
3535
}
3636
}

src/capacity/CapacityCalculatorBase.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,27 @@ export default class CapacityCalculatorBase {
103103
// These values determine how many minutes worth of metrics
104104
let statisticCount = 5;
105105
let statisticSpanMinutes = 1;
106-
let statisticType = 'Average';
106+
let statisticType = 'Sum';
107107

108108
let EndTime = new Date();
109109
let StartTime = new Date();
110110
StartTime.setTime(EndTime - (60000 * statisticSpanMinutes * statisticCount));
111111
let MetricName = isRead ? 'ConsumedReadCapacityUnits' : 'ConsumedWriteCapacityUnits';
112112
let Dimensions = this.getDimensions(tableName, globalSecondaryIndexName);
113+
let period = (statisticSpanMinutes * 60);
113114
let params = {
114115
Namespace: 'AWS/DynamoDB',
115116
MetricName,
116117
Dimensions,
117118
StartTime,
118119
EndTime,
119-
Period: (statisticSpanMinutes * 60),
120+
Period: period,
120121
Statistics: [ statisticType ],
121122
Unit: 'Count'
122123
};
123124

124125
let statistics = await this.cw.getMetricStatisticsAsync(params);
126+
statistics.period = period;
125127
let value = this.getProjectedValue(statistics);
126128
let result: ConsumedCapacityDesc = {
127129
tableName,

0 commit comments

Comments
 (0)