Search in sources :

Example 1 with Datapoint

use of com.amazonaws.services.cloudwatch.model.Datapoint in project photon-model by vmware.

the class AWSUtils method calculateAverageBurnRate.

/**
 * Calculate the average burn rate, given a list of datapoints from Amazon AWS.
 */
public static Double calculateAverageBurnRate(List<Datapoint> dpList) {
    if (dpList.size() <= 1) {
        return null;
    }
    Datapoint oldestDatapoint = dpList.get(0);
    Datapoint latestDatapoint = dpList.get(dpList.size() - 1);
    // OldestDatapoint value is 0 and the latestDatapoint value is 3.
    for (Datapoint datapoint : dpList.subList(1, dpList.size() - 1)) {
        if (latestDatapoint.getAverage() > oldestDatapoint.getAverage()) {
            break;
        }
        oldestDatapoint = datapoint;
    }
    double averageBurnRate = (latestDatapoint.getAverage() - oldestDatapoint.getAverage()) / getDateDifference(oldestDatapoint.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
    averageBurnRate = (averageBurnRate < 0 ? 0 : averageBurnRate);
    return averageBurnRate;
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint)

Example 2 with Datapoint

use of com.amazonaws.services.cloudwatch.model.Datapoint in project photon-model by vmware.

the class TestAWSUtils method testAverageBurnRateCalculationExpectNull.

/**
 * Test that expects null response since there arn't sufficient datapoints
 */
@Test
public void testAverageBurnRateCalculationExpectNull() {
    List<Datapoint> dpList = new ArrayList<>();
    dpList.add(new Datapoint());
    Double burnRate = AWSUtils.calculateAverageBurnRate(dpList);
    assertTrue("Received a non-null response", burnRate == null);
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Datapoint

use of com.amazonaws.services.cloudwatch.model.Datapoint in project photon-model by vmware.

the class TestAWSUtils method testCurrentBurnRateCalculationExpectNull.

/**
 * Test that expects null response since there arn't sufficient datapoints
 */
@Test
public void testCurrentBurnRateCalculationExpectNull() {
    List<Datapoint> dpList = new ArrayList<>();
    dpList.add(new Datapoint());
    Double burnRate = AWSUtils.calculateCurrentBurnRate(dpList);
    assertTrue("Received a non-null response", burnRate == null);
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Datapoint

use of com.amazonaws.services.cloudwatch.model.Datapoint in project beam by apache.

the class SimplifiedKinesisClient method getBacklogBytes.

/**
 * Gets total size in bytes of all events that remain in Kinesis stream between specified
 * instants.
 *
 * @return total size in bytes of all Kinesis events after specified instant
 */
public long getBacklogBytes(final String streamName, final Instant countSince, final Instant countTo) throws TransientKinesisException {
    return wrapExceptions(() -> {
        Minutes period = Minutes.minutesBetween(countSince, countTo);
        if (period.isLessThan(Minutes.ONE)) {
            return 0L;
        }
        GetMetricStatisticsRequest request = createMetricStatisticsRequest(streamName, countSince, countTo, period);
        long totalSizeInBytes = 0;
        GetMetricStatisticsResult result = cloudWatch.getMetricStatistics(request);
        for (Datapoint point : result.getDatapoints()) {
            totalSizeInBytes += point.getSum().longValue();
        }
        return totalSizeInBytes;
    });
}
Also used : Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) GetMetricStatisticsRequest(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest) GetMetricStatisticsResult(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult) Minutes(org.joda.time.Minutes)

Example 5 with Datapoint

use of com.amazonaws.services.cloudwatch.model.Datapoint in project beam by apache.

the class SimplifiedKinesisClientTest method shouldCountBytesWhenMultipleDataPointsReturned.

@Test
public void shouldCountBytesWhenMultipleDataPointsReturned() 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), new Datapoint().withSum(3.0), new Datapoint().withSum(2.0));
    when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);
    long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);
    assertThat(backlogBytes).isEqualTo(6L);
}
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