software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse Java Examples

The following examples show how to use software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PutMetricData.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void putMetData(CloudWatchClient cw, Double dataPoint ) {

        try {
            Dimension dimension = Dimension.builder()
                .name("UNIQUE_PAGES")
                .value("URLS").build();

            MetricDatum datum = MetricDatum.builder()
                .metricName("PAGES_VISITED")
                .unit(StandardUnit.NONE)
                .value(dataPoint)
                .dimensions(dimension).build();

            PutMetricDataRequest request = PutMetricDataRequest.builder()
                .namespace("SITE/TRAFFIC")
                .metricData(datum).build();

            PutMetricDataResponse response = cw.putMetricData(request);

        } catch (CloudWatchException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        System.out.printf("Successfully put data point %f", dataPoint);
        // snippet-end:[cloudwatch.java2.put_metric_data.main]
    }
 
Example #2
Source File: CloudWatchMetricsPublisherTest.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetricsPublisher() {
    final CompletableFuture<PutMetricDataResponse> putResponseFuture = new CompletableFuture<>();
    putResponseFuture.complete(PutMetricDataResponse.builder().build());
    when(cloudWatchClient.putMetricData(any(PutMetricDataRequest.class))).thenReturn(putResponseFuture);

    List<MetricDatumWithKey<CloudWatchMetricKey>> dataToPublish = constructMetricDatumWithKeyList(25);
    List<Map<String, MetricDatum>> expectedData = constructMetricDatumListMap(dataToPublish);
    publisher.publishMetrics(dataToPublish);
    
    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    Mockito.verify(cloudWatchClient, Mockito.atLeastOnce()).putMetricData(argument.capture());

    List<PutMetricDataRequest> requests = argument.getAllValues();
    Assert.assertEquals(expectedData.size(), requests.size());

    for (int i = 0; i < requests.size(); i++) {
        assertMetricData(expectedData.get(i), requests.get(i));
    }

}
 
Example #3
Source File: MetricsPublisherImplTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void beforeEach() {
    when(providerCloudWatchProvider.get()).thenReturn(providerCloudWatchClient);
    when(providerCloudWatchClient.putMetricData(any(PutMetricDataRequest.class)))
        .thenReturn(mock(PutMetricDataResponse.class));
}