use of com.amazonaws.services.cloudwatch.model.Datapoint in project photon-model by vmware.
the class AWSUtils method calculateCurrentBurnRate.
/**
* Calculate the current burn rate, given a list of datapoints from Amazon AWS.
*/
public static Double calculateCurrentBurnRate(List<Datapoint> dpList) {
if (dpList.size() <= 7) {
return null;
}
Datapoint dayOldDatapoint = dpList.get(dpList.size() - 7);
Datapoint latestDatapoint = dpList.get(dpList.size() - 1);
// OldestDatapoint value is 0 and the latestDatapoint value is 3.
for (Datapoint datapoint : dpList.subList(dpList.size() - 6, dpList.size() - 1)) {
if (latestDatapoint.getAverage() > dayOldDatapoint.getAverage()) {
break;
}
dayOldDatapoint = datapoint;
}
double currentBurnRate = (latestDatapoint.getAverage() - dayOldDatapoint.getAverage()) / getDateDifference(dayOldDatapoint.getTimestamp(), latestDatapoint.getTimestamp(), TimeUnit.HOURS);
// If there are only 2 datapoints and the oldestDatapoint is greater than the
// latestDatapoint, value will be negative.
// Eg: oldestDatapoint = 5 and latestDatapoint = 0, when the billing cycle is reset.
// In such cases, set the burn rate value to 0
currentBurnRate = (currentBurnRate < 0 ? 0 : currentBurnRate);
return currentBurnRate;
}
use of com.amazonaws.services.cloudwatch.model.Datapoint in project photon-model by vmware.
the class TestAWSUtils method getDatapoint.
private Datapoint getDatapoint(Double average, Date timestamp) {
Datapoint dp = new Datapoint();
dp.setAverage(average);
dp.setTimestamp(timestamp);
return dp;
}
use of com.amazonaws.services.cloudwatch.model.Datapoint in project beam by apache.
the class SimplifiedKinesisClientTest method shouldCountBytesWhenSingleDataPointReturned.
@Test
public void shouldCountBytesWhenSingleDataPointReturned() throws Exception {
Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
GetMetricStatisticsRequest metricStatisticsRequest = underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
GetMetricStatisticsResult result = new GetMetricStatisticsResult().withDatapoints(new Datapoint().withSum(1.0));
when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
assertThat(backlogBytes).isEqualTo(1L);
}
Aggregations