Search in sources :

Example 6 with PutMetricDataRequest

use of com.amazonaws.services.cloudwatch.model.PutMetricDataRequest in project camel by apache.

the class CwComponentTest method useDefaultValuesForMetricUnitAndMetricValue.

@Test
public void useDefaultValuesForMetricUnitAndMetricValue() throws Exception {
    template.send("direct:start", ExchangePattern.InOnly, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
        }
    });
    ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(cloudWatchClient).putMetricData(argument.capture());
    assertEquals("errorCount", argument.getValue().getMetricData().get(0).getMetricName());
    assertEquals(Double.valueOf(1), argument.getValue().getMetricData().get(0).getValue());
    assertEquals(StandardUnit.Count.toString(), argument.getValue().getMetricData().get(0).getUnit());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) Test(org.junit.Test)

Example 7 with PutMetricDataRequest

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

Example 8 with PutMetricDataRequest

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

Example 9 with PutMetricDataRequest

use of com.amazonaws.services.cloudwatch.model.PutMetricDataRequest in project chassis by Kixeye.

the class MetricsCloudWatchReporter method addDatum.

private void addDatum(String name, double value, LinkedList<PutMetricDataRequest> requests, Date timestamp) {
    if (logger.isDebugEnabled()) {
        logger.debug("Adding Datum {} with value {} at {}", name, value, timestamp);
    }
    if (requests.isEmpty() || requests.getLast().getMetricData().size() == MAX_CLOUDWATCH_DATUM_PER_REQUEST) {
        requests.add(createRequest());
    }
    PutMetricDataRequest request = requests.getLast();
    MetricDatum datum = new MetricDatum().withTimestamp(timestamp).withValue(value).withMetricName(name).withUnit(StandardUnit.None).withDimensions(createDimensions());
    request.withMetricData(datum);
}
Also used : PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum)

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