use of com.amazonaws.services.cloudwatch.model.PutMetricDataRequest in project camel by apache.
the class CwComponentTest method setsMeticDimensions.
@Test
public void setsMeticDimensions() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
dimensionsMap.put("keyOne", "valueOne");
dimensionsMap.put("keyTwo", "valueTwo");
exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
Dimension dimension = dimensions.get(0);
assertThat(dimensions.size(), is(2));
assertEquals("keyOne", dimension.getName());
assertEquals("valueOne", dimension.getValue());
}
use of com.amazonaws.services.cloudwatch.model.PutMetricDataRequest in project camel by apache.
the class CwComponentTest method sendMetricFromHeaderValues.
@Test
public void sendMetricFromHeaderValues() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(CwConstants.METRIC_NAMESPACE, "camel.apache.org/overriden");
exchange.getIn().setHeader(CwConstants.METRIC_NAME, "OverridenMetric");
exchange.getIn().setHeader(CwConstants.METRIC_VALUE, Double.valueOf(3));
exchange.getIn().setHeader(CwConstants.METRIC_UNIT, StandardUnit.Bytes.toString());
exchange.getIn().setHeader(CwConstants.METRIC_TIMESTAMP, LATER);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
assertEquals("camel.apache.org/overriden", argument.getValue().getNamespace());
assertEquals("OverridenMetric", argument.getValue().getMetricData().get(0).getMetricName());
assertEquals(Double.valueOf(3), argument.getValue().getMetricData().get(0).getValue());
assertEquals(StandardUnit.Bytes.toString(), argument.getValue().getMetricData().get(0).getUnit());
assertEquals(LATER, argument.getValue().getMetricData().get(0).getTimestamp());
}
use of com.amazonaws.services.cloudwatch.model.PutMetricDataRequest 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.PutMetricDataRequest 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.PutMetricDataRequest 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");
}
Aggregations