use of software.amazon.awssdk.services.cloudwatch.model.ListMetricsResponse in project aws-doc-sdk-examples by awsdocs.
the class ListMetrics method listMets.
// snippet-start:[cloudwatch.java2.list_metrics.main]
public static void listMets(CloudWatchClient cw, String namespace) {
boolean done = false;
String nextToken = null;
try {
while (!done) {
ListMetricsResponse response;
if (nextToken == null) {
ListMetricsRequest request = ListMetricsRequest.builder().namespace(namespace).build();
response = cw.listMetrics(request);
} else {
ListMetricsRequest request = ListMetricsRequest.builder().namespace(namespace).nextToken(nextToken).build();
response = cw.listMetrics(request);
}
for (Metric metric : response.metrics()) {
System.out.printf("Retrieved metric %s", metric.metricName());
System.out.println();
}
if (response.nextToken() == null) {
done = true;
} else {
nextToken = response.nextToken();
}
}
} catch (CloudWatchException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations