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);
}
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);
}
Aggregations