Search in sources :

Example 1 with PutMetricDataRequest

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with PutMetricDataRequest

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) Test(org.junit.Test)

Example 3 with PutMetricDataRequest

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.");
}
Also used : PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 4 with PutMetricDataRequest

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);
}
Also used : AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

Example 5 with PutMetricDataRequest

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");
}
Also used : PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Test(org.junit.Test)

Aggregations

PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)9 MetricDatum (com.amazonaws.services.cloudwatch.model.MetricDatum)6 Test (org.junit.Test)5 Exchange (org.apache.camel.Exchange)4 Processor (org.apache.camel.Processor)4 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)2 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1