Search in sources :

Example 1 with ListMetricsResult

use of com.amazonaws.services.cloudwatch.model.ListMetricsResult in project iep by Netflix.

the class PaginationTest method cloudwatch.

@Test
public void cloudwatch() throws Exception {
    SortedSet<String> pages = newPageSet(5);
    final Iterator<String> reqIt = pages.iterator();
    final Iterator<String> resIt = pages.iterator();
    Function<ListMetricsRequest, ListMetricsResult> f = r -> {
        if (r.getNextToken() != null) {
            Assert.assertEquals(reqIt.next(), r.getNextToken());
        }
        return new ListMetricsResult().withNextToken(resIt.hasNext() ? resIt.next() : null);
    };
    Publisher<ListMetricsResult> publisher = Pagination.createPublisher(new ListMetricsRequest(), f);
    Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getNextToken() != null).map(ListMetricsResult::getNextToken).blockingIterable();
    SortedSet<String> results = new TreeSet<>();
    for (String s : iter) {
        results.add(s);
    }
    Assert.assertEquals(pages, results);
    Assert.assertFalse(reqIt.hasNext());
}
Also used : ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) SortedSet(java.util.SortedSet) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Function(java.util.function.Function) TreeSet(java.util.TreeSet) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Iterator(java.util.Iterator) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Publisher(org.reactivestreams.Publisher) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) ListHostedZonesRequest(com.amazonaws.services.route53.model.ListHostedZonesRequest) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) Assert(org.junit.Assert) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) TreeSet(java.util.TreeSet) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) Test(org.junit.Test)

Example 2 with ListMetricsResult

use of com.amazonaws.services.cloudwatch.model.ListMetricsResult in project aws-doc-sdk-examples by awsdocs.

the class ListMetrics method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply a metric name and metric namespace\n" + "Ex: ListMetrics <metric-name> <metric-namespace>\n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String name = args[0];
    String namespace = args[1];
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    boolean done = false;
    while (!done) {
        ListMetricsRequest request = new ListMetricsRequest().withMetricName(name).withNamespace(namespace);
        ListMetricsResult response = cw.listMetrics(request);
        for (Metric metric : response.getMetrics()) {
            System.out.printf("Retrieved metric %s", metric.getMetricName());
        }
        request.setNextToken(response.getNextToken());
        if (response.getNextToken() == null) {
            done = true;
        }
    }
}
Also used : AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) Metric(com.amazonaws.services.cloudwatch.model.Metric)

Aggregations

ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)2 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1 Metric (com.amazonaws.services.cloudwatch.model.Metric)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)1 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)1 DescribeTargetGroupsRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest)1 DescribeTargetGroupsResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult)1 ListClustersRequest (com.amazonaws.services.elasticmapreduce.model.ListClustersRequest)1 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)1 ListHostedZonesRequest (com.amazonaws.services.route53.model.ListHostedZonesRequest)1