Example usage for com.amazonaws.services.cloudwatch.model PutMetricDataRequest getMetricData

List of usage examples for com.amazonaws.services.cloudwatch.model PutMetricDataRequest getMetricData

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudwatch.model PutMetricDataRequest getMetricData.

Prototype


public java.util.List<MetricDatum> getMetricData() 

Source Link

Document

The data for the metric.

Usage

From source file:com.amediamanager.metrics.MetricBatcher.java

License:Apache License

protected void sendBatch(Map<String, Collection<MetricDatum>> datums) {
    for (final Map.Entry<String, Collection<MetricDatum>> e : datums.entrySet()) {
        for (final List<MetricDatum> batch : Lists.partition(Lists.newLinkedList(e.getValue()), BATCH_SIZE)) {
            cloudWatch.putMetricDataAsync(
                    new PutMetricDataRequest().withNamespace(e.getKey()).withMetricData(batch),
                    new AsyncHandler<PutMetricDataRequest, Void>() {

                        @Override
                        public void onError(Exception exception) {
                            LOG.error("PutMetricData failed", exception);
                            LOG.info("Requeueing metric data.");
                            queuedDatums.putAll(e.getKey(), batch);
                        }/*from w ww.ja  va2s  . co m*/

                        @Override
                        public void onSuccess(PutMetricDataRequest request, Void result) {
                            LOG.info("Successfully put " + request.getMetricData().size()
                                    + " datums for namespace " + request.getNamespace());
                            LOG.debug("Request", request);
                        }

                    });
        }
    }
}

From source file:com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter.java

License:Apache License

@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;/*from w ww . j a  va  2 s  . c  o m*/
    }

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

From source file:org.apache.nifi.processors.aws.cloudwatch.MockPutCloudWatchMetric.java

License:Apache License

protected PutMetricDataResult putMetricData(PutMetricDataRequest metricDataRequest)
        throws AmazonClientException {
    putMetricDataCallCount++;//from www  .  j av a2  s  .c  om
    actualNamespace = metricDataRequest.getNamespace();
    actualMetricData = metricDataRequest.getMetricData();

    if (throwException != null) {
        throw throwException;
    }

    return result;
}

From source file:org.web.online.cloudwatch.tomcat.valve.ElapsedTimeAggregator.java

License:Apache License

/**
 * Collect the aggregated values (min, max, count, sum) into a
 * StatisticSet and send the data to Cloud Watch
 *///from  ww  w. java2s .com
@Override
public void run() {

    PutMetricDataRequest localPutMetricDataRequest = zeroValuePutMetricDataRequest;
    MetricDatum metricDatum = localPutMetricDataRequest.getMetricData().get(0);

    if (sampleCount > 0) {
        localPutMetricDataRequest = putMetricDataRequest;
        metricDatum = localPutMetricDataRequest.getMetricData().get(0);
        StatisticSet statisticSet = metricDatum.getStatisticValues();
        synchronized (lock) {
            statisticSet.setMaximum(maximum);
            statisticSet.setMinimum(minimum);
            statisticSet.setSampleCount(sampleCount);
            statisticSet.setSum(sum);

            minimum = Double.MAX_VALUE;
            maximum = Double.MIN_VALUE;
            sampleCount = 0;
            sum = 0;
        }
    }

    metricDatum.setTimestamp(new Date());

    if (log.isDebugEnabled()) {
        log.debug("sending " + localPutMetricDataRequest);
    }

    cloudWatchClient.putMetricData(localPutMetricDataRequest);
}