Search in sources :

Example 6 with Datapoint

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;
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint)

Example 7 with Datapoint

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;
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint)

Example 8 with Datapoint

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);
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) GetMetricStatisticsRequest(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest) Instant(org.joda.time.Instant) GetMetricStatisticsResult(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult) Minutes(org.joda.time.Minutes) Test(org.junit.Test)

Aggregations

Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)8 Test (org.junit.Test)4 GetMetricStatisticsRequest (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest)3 GetMetricStatisticsResult (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult)3 Minutes (org.joda.time.Minutes)3 ArrayList (java.util.ArrayList)2 Instant (org.joda.time.Instant)2