use of com.amazonaws.services.cloudwatch.model.ListMetricsRequest 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());
}
use of com.amazonaws.services.cloudwatch.model.ListMetricsRequest in project wildfly-camel by wildfly-extras.
the class CloudWatchIntegrationTest method testKeyValueOperations.
@Test
public void testKeyValueOperations() throws Exception {
AmazonCloudWatchClient cwClient = provider.getClient();
Assume.assumeNotNull("AWS client not null", cwClient);
List<Metric> staleMetrics = cwClient.listMetrics(new ListMetricsRequest().withNamespace(NAMESPACE)).getMetrics().stream().filter(metric -> !metric.getMetricName().startsWith(CloudWatchIntegrationTest.class.getSimpleName()) || System.currentTimeMillis() - AWSUtils.toEpochMillis(metric.getMetricName()) > //
AWSUtils.TWO_WEEKS).collect(Collectors.toList());
if (staleMetrics.size() > 0) {
Assert.fail("Found '" + CloudWatchIntegrationTest.class.getName() + "-*' metrics older than two weeks: " + staleMetrics);
}
WildFlyCamelContext camelctx = new WildFlyCamelContext();
camelctx.getNamingContext().bind("cwClient", cwClient);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:metrics").to("aws-cw://" + NAMESPACE + "?amazonCwClient=#cwClient");
}
});
camelctx.start();
try {
Map<String, Object> headers = new HashMap<>();
headers.put(CwConstants.METRIC_NAME, METRIC_NAME);
headers.put(CwConstants.METRIC_DIMENSION_NAME, DIM_NAME);
headers.put(CwConstants.METRIC_DIMENSION_VALUE, DIM_VALUE);
ListMetricsRequest request = new ListMetricsRequest().withNamespace(NAMESPACE).withMetricName(METRIC_NAME).withDimensions(new DimensionFilter().withName(DIM_NAME).withValue(DIM_VALUE));
List<Metric> metrics = Collections.emptyList();
ProducerTemplate producer = camelctx.createProducerTemplate();
for (int i = 100; i < 105 && metrics.size() == 0; i++) {
producer.sendBodyAndHeaders("direct:metrics", new Double(i), headers);
metrics = cwClient.listMetrics(request).getMetrics();
System.out.println("metrics #" + i + ": " + metrics);
Thread.sleep(1000);
}
// It may take several minutes for the metric to show up
// Assert.assertEquals(1, metrics.size());
} finally {
camelctx.stop();
}
}
use of com.amazonaws.services.cloudwatch.model.ListMetricsRequest 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();
ListMetricsRequest request = new ListMetricsRequest().withMetricName(name).withNamespace(namespace);
boolean done = false;
while (!done) {
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;
}
}
}
Aggregations