Search in sources :

Example 1 with PutMetricDataRequest

use of software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest in project iep by Netflix.

the class PaginationTest method cloudwatchPut.

@Test
public void cloudwatchPut() throws Exception {
    final AtomicInteger n = new AtomicInteger();
    Function<PutMetricDataRequest, PutMetricDataResponse> f = r -> {
        if (n.getAndIncrement() > 0) {
            Assert.fail("non-paginated API called more than once");
        }
        return PutMetricDataResponse.builder().build();
    };
    Publisher<PutMetricDataResponse> publisher = Pagination.createPublisher(PutMetricDataRequest.builder().build(), f);
    Iterable<PutMetricDataResponse> iter = Flowable.fromPublisher(publisher).blockingIterable();
    int count = 0;
    for (PutMetricDataResponse r : iter) {
        ++count;
    }
    Assert.assertEquals(1, count);
}
Also used : SortedSet(java.util.SortedSet) ListResourceRecordSetsResponse(software.amazon.awssdk.services.route53.model.ListResourceRecordSetsResponse) DescribeTargetGroupsRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ListMetricsRequest(software.amazon.awssdk.services.cloudwatch.model.ListMetricsRequest) ListHostedZonesResponse(software.amazon.awssdk.services.route53.model.ListHostedZonesResponse) DescribeAutoScalingGroupsResponse(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsResponse) ListClustersRequest(software.amazon.awssdk.services.emr.model.ListClustersRequest) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) DescribeInstancesResponse(software.amazon.awssdk.services.ec2.model.DescribeInstancesResponse) Map(java.util.Map) DescribeInstancesRequest(software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest) PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) Iterator(java.util.Iterator) ScanResponse(software.amazon.awssdk.services.dynamodb.model.ScanResponse) Publisher(org.reactivestreams.Publisher) ListClustersResponse(software.amazon.awssdk.services.emr.model.ListClustersResponse) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DescribeTargetGroupsResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeTargetGroupsResponse) PutMetricDataResponse(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse) ListHostedZonesRequest(software.amazon.awssdk.services.route53.model.ListHostedZonesRequest) DescribeAutoScalingGroupsRequest(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsRequest) ListResourceRecordSetsRequest(software.amazon.awssdk.services.route53.model.ListResourceRecordSetsRequest) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DescribeLoadBalancersRequest(software.amazon.awssdk.services.autoscaling.model.DescribeLoadBalancersRequest) Assert(org.junit.Assert) DescribeLoadBalancersResponse(software.amazon.awssdk.services.autoscaling.model.DescribeLoadBalancersResponse) ListMetricsResponse(software.amazon.awssdk.services.cloudwatch.model.ListMetricsResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) PutMetricDataResponse(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse) Test(org.junit.Test)

Example 2 with PutMetricDataRequest

use of software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest in project aws-doc-sdk-examples by awsdocs.

the class PutMetricData method putMetData.

// snippet-start:[cloudwatch.java2.put_metric_data.main]
public static void putMetData(CloudWatchClient cw, Double dataPoint) {
    try {
        Dimension dimension = Dimension.builder().name("UNIQUE_PAGES").value("URLS").build();
        // Set an Instant object
        String time = ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT);
        Instant instant = Instant.parse(time);
        MetricDatum datum = MetricDatum.builder().metricName("PAGES_VISITED").unit(StandardUnit.NONE).value(dataPoint).timestamp(instant).dimensions(dimension).build();
        PutMetricDataRequest request = PutMetricDataRequest.builder().namespace("SITE/TRAFFIC").metricData(datum).build();
        cw.putMetricData(request);
    } catch (CloudWatchException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.printf("Successfully put data point %f", dataPoint);
}
Also used : CloudWatchException(software.amazon.awssdk.services.cloudwatch.model.CloudWatchException) PutMetricDataRequest(software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest) Instant(java.time.Instant) MetricDatum(software.amazon.awssdk.services.cloudwatch.model.MetricDatum) Dimension(software.amazon.awssdk.services.cloudwatch.model.Dimension)

Aggregations

PutMetricDataRequest (software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest)2 Flowable (io.reactivex.Flowable)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1 Publisher (org.reactivestreams.Publisher)1 DescribeAutoScalingGroupsRequest (software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResponse (software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsResponse)1 DescribeLoadBalancersRequest (software.amazon.awssdk.services.autoscaling.model.DescribeLoadBalancersRequest)1 DescribeLoadBalancersResponse (software.amazon.awssdk.services.autoscaling.model.DescribeLoadBalancersResponse)1 CloudWatchException (software.amazon.awssdk.services.cloudwatch.model.CloudWatchException)1