Search in sources :

Example 1 with MetricDatum

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.");
}
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 2 with MetricDatum

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);
}
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 3 with MetricDatum

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

Example 4 with MetricDatum

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());
}
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 5 with MetricDatum

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

Aggregations

MetricDatum (com.amazonaws.services.cloudwatch.model.MetricDatum)7 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)6 Test (org.junit.Test)2 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1