use of com.amazonaws.services.cloudwatch.model.MetricDatum in project chassis by Kixeye.
the class MetricsCloudWatchReporter method report.
@Override
@SuppressWarnings("rawtypes")
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
logger.info("Starting metrics publishing to AWS CloudWatch.");
LinkedList<PutMetricDataRequest> requests = new LinkedList<>();
addMetricData(gauges, counters, histograms, meters, timers, requests, new Date());
if (requests.isEmpty()) {
logger.debug("No metric data to send to AWS.");
return;
}
for (PutMetricDataRequest request : requests) {
try {
for (MetricDatum datum : request.getMetricData()) {
logger.debug("Sending metric " + datum);
}
cloudWatch.putMetricData(request);
} catch (Exception e) {
logger.error("Failed to log metrics to CloudWatch discarding metrics for this attempt...", e);
return;
}
}
logger.info("Finished metrics publishing to AWS CloudWatch.");
}
use of com.amazonaws.services.cloudwatch.model.MetricDatum in project aws-doc-sdk-examples by awsdocs.
the class PutMetricData method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a data point:\n" + "Ex: PutMetricData <data_point>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
Double data_point = Double.parseDouble(args[0]);
final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
Dimension dimension = new Dimension().withName("UNIQUE_PAGES").withValue("URLS");
MetricDatum datum = new MetricDatum().withMetricName("PAGES_VISITED").withUnit(StandardUnit.None).withValue(data_point).withDimensions(dimension);
PutMetricDataRequest request = new PutMetricDataRequest().withNamespace("SITE/TRAFFIC").withMetricData(datum);
PutMetricDataResult response = cw.putMetricData(request);
System.out.printf("Successfully put data point %f", data_point);
}
use of com.amazonaws.services.cloudwatch.model.MetricDatum in project jmxtrans by jmxtrans.
the class CloudWatchWriterTests method testValidationWithoutSettings.
@Test
public void testValidationWithoutSettings() throws Exception {
writer.doWrite(dummyServer(), dummyQuery(), dummyResults());
verify(cloudWatchClient).putMetricData(requestCaptor.capture());
PutMetricDataRequest request = requestCaptor.getValue();
assertThat(request).isNotNull();
assertThat(request.getNamespace()).isEqualTo("testNS");
assertThat(request.getMetricData()).hasSize(1);
MetricDatum metricDatum = request.getMetricData().get(0);
assertThat(metricDatum.getMetricName()).isEqualTo("ObjectPendingFinalizationCount");
assertThat(metricDatum.getValue()).isEqualTo(10);
assertThat(metricDatum.getDimensions().size()).isEqualTo(2);
assertThat(metricDatum.getDimensions().get(0).getName()).isEqualTo("SomeKey");
assertThat(metricDatum.getDimensions().get(1).getName()).isEqualTo("InstanceId");
}
use of com.amazonaws.services.cloudwatch.model.MetricDatum in project camel by apache.
the class CwComponentTest method sendManuallyCreatedMetric.
@Test
public void sendManuallyCreatedMetric() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
MetricDatum metricDatum = new MetricDatum().withMetricName("errorCount").withValue(Double.valueOf(0));
exchange.getIn().setBody(metricDatum);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
assertEquals("errorCount", argument.getValue().getMetricData().get(0).getMetricName());
assertEquals(Double.valueOf(0), argument.getValue().getMetricData().get(0).getValue());
}
use of com.amazonaws.services.cloudwatch.model.MetricDatum in project camel by apache.
the class CwProducer method process.
public void process(Exchange exchange) throws Exception {
List<MetricDatum> metricData = getMetricData(exchange);
PutMetricDataRequest request = new PutMetricDataRequest().withMetricData(metricData).withNamespace(determineNameSpace(exchange));
log.info("Sending request [{}] from exchange [{}]...", request, exchange);
getEndpoint().getCloudWatchClient().putMetricData(request);
}
Aggregations