forked from channl/dynamodb-lambda-autoscale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CapacityCalculator.js
39 lines (33 loc) · 1.23 KB
/
CapacityCalculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* @flow */
import { invariant } from './Global';
import { Region } from './configuration/Region';
import CapacityCalculatorBase from './capacity/CapacityCalculatorBase';
import type { GetMetricStatisticsResponse } from 'aws-sdk-promise';
import type { StatisticSettings } from './flow/FlowTypes';
export default class CapacityCalculator extends CapacityCalculatorBase {
// Get the region
getCloudWatchRegion() {
return Region;
}
getStatisticSettings(): StatisticSettings {
return {
count: 5,
spanMinutes: 1,
type: 'Sum',
};
}
// Gets the projected capacity value based on the cloudwatch datapoints
getProjectedValue(settings: StatisticSettings, data: GetMetricStatisticsResponse) {
invariant(data != null, 'Parameter \'data\' is not set');
if (data.Datapoints.length === 0) {
return 0;
}
// Default algorithm for projecting a good value for the current ConsumedThroughput is:
// 1. Query 5 average readings each spanning a minute
// 2. Select the Max value from those 5 readings
let spanSeconds = settings.spanMinutes * 60;
let averages = data.Datapoints.map(dp => dp.Sum / spanSeconds);
let projectedValue = Math.max(...averages);
return projectedValue;
}
}