Example usage for com.amazonaws.services.cloudwatch.model MetricDatum getMetricName

List of usage examples for com.amazonaws.services.cloudwatch.model MetricDatum getMetricName

Introduction

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

Prototype


public String getMetricName() 

Source Link

Document

The name of the metric.

Usage

From source file:com.amazon.kinesis.streaming.agent.metrics.CWMetricKey.java

License:Open Source License

/**
 * @param datum data point//from w w w .  java  2  s  .co m
 */

public CWMetricKey(MetricDatum datum) {
    this.dimensions = datum.getDimensions();
    this.metricName = datum.getMetricName();
}

From source file:com.amazon.kinesis.streaming.agent.metrics.DefaultCWMetricsPublisher.java

License:Open Source License

@Override
public void publishMetrics(List<MetricDatumWithKey<CWMetricKey>> dataToPublish) {
    for (int startIndex = 0; startIndex < dataToPublish.size(); startIndex += BATCH_SIZE) {
        int endIndex = Math.min(dataToPublish.size(), startIndex + BATCH_SIZE);

        PutMetricDataRequest request = new PutMetricDataRequest();
        request.setNamespace(namespace);

        List<MetricDatum> metricData = new ArrayList<MetricDatum>();
        for (int i = startIndex; i < endIndex; i++) {
            MetricDatum metric = dataToPublish.get(i).datum;
            if (!metric.getMetricName().startsWith("."))
                metricData.add(dataToPublish.get(i).datum);
        }/*from   w  w  w .  ja v  a  2  s.  c  om*/
        if (metricData.isEmpty())
            return;

        request.setMetricData(metricData);
        try {
            cloudWatchClient.putMetricData(request);

            LOG.info(String.format("Successfully published %d datums.", endIndex - startIndex));
        } catch (AmazonClientException e) {
            LOG.warn(String.format("Could not publish %d datums to CloudWatch", endIndex - startIndex), e);
        }
    }
}

From source file:com.amazon.kinesis.streaming.agent.metrics.LogMetricsScope.java

License:Open Source License

@Override
protected void realCommit() {
    if (!data.values().isEmpty()) {
        StringBuilder output = new StringBuilder();
        output.append("Metrics:\n");

        output.append("Dimensions: ");
        boolean needsComma = false;
        for (Dimension dimension : getDimensions()) {
            output.append(String.format("%s[%s: %s]", needsComma ? ", " : "", dimension.getName(),
                    dimension.getValue()));
            needsComma = true;//w w  w  . j  a  va 2  s  .  co  m
        }
        output.append("\n");

        for (MetricDatum datum : data.values()) {
            StatisticSet statistics = datum.getStatisticValues();
            output.append(
                    String.format("Name=%50s\tMin=%.2f\tMax=%.2f\tCount=%.2f\tSum=%.2f\tAvg=%.2f\tUnit=%s\n",
                            datum.getMetricName(), statistics.getMinimum(), statistics.getMaximum(),
                            statistics.getSampleCount(), statistics.getSum(),
                            statistics.getSum() / statistics.getSampleCount(), datum.getUnit()));
        }
        LOGGER.debug(output.toString());
    }
}

From source file:com.amazon.kinesis.streaming.agent.metrics.MetricAccumulatingQueue.java

License:Open Source License

private void accumulate(MetricDatum oldDatum, MetricDatum newDatum) {
    if (!oldDatum.getUnit().equals(newDatum.getUnit())) {
        throw new IllegalArgumentException("Unit mismatch for datum named " + oldDatum.getMetricName());
    }//from   w  w  w  .  j a va2s .  c om

    StatisticSet oldStats = oldDatum.getStatisticValues();
    StatisticSet newStats = newDatum.getStatisticValues();

    oldStats.setSampleCount(oldStats.getSampleCount() + newStats.getSampleCount());
    oldStats.setMaximum(Math.max(oldStats.getMaximum(), newStats.getMaximum()));
    oldStats.setMinimum(Math.min(oldStats.getMinimum(), newStats.getMinimum()));
    oldStats.setSum(oldStats.getSum() + newStats.getSum());
}

From source file:com.boundlessgeo.suite.geoserver.cloudwatch.aws.CloudwatchSender.java

License:Open Source License

/**
 * Invoked by spring on a timer to get and send from all metric providers
 *//*from w ww.  j a  va  2 s .  c  o m*/
public void sendAllMetrics() {
    if (!enabled) {
        logger.debug("Metrics are disabled...returning");
        return;
    }
    logger.debug("Sending all metrics");
    for (MetricProvider mp : providers) {
        if (!mp.getEnabled())
            continue;
        for (final MetricDatum md : mp.getMetrics()) {
            try {
                PutMetricDataRequest request = new PutMetricDataRequest().withNamespace("geoserver")
                        .withMetricData(md);
                logger.trace("Sending statistic {}", md.getMetricName());
                ListenableFuture<java.lang.Void> f = JdkFutureAdapters
                        .listenInPoolThread(cloudwatch.putMetricDataAsync(request));
                Futures.addCallback(f, new FutureCallback<java.lang.Void>() {
                    public void onSuccess(java.lang.Void ignored) {
                        logger.trace("Sent statistic {}", md.getMetricName());
                    }

                    public void onFailure(Throwable ex) {
                        logger.error("Error sending metric: {}", md.getMetricName(), ex);
                    }
                });
            } catch (AmazonClientException ex) {
                logger.warn("Error sending AWS metric {}", md.getMetricName());
            }
        }
    }
}

From source file:com.boundlessgeo.suite.geoserver.cloudwatch.aws.CloudwatchSender.java

License:Open Source License

/**
 * Invoked by spring on a timer to get and send from all metric providers
 *//*from   w  w  w  . ja v  a 2  s  . c om*/
public void sendAllMetricsToConsole() {
    if (!enabled) {
        logger.debug("Metrics are disabled...returning");
        return;
    }
    logger.debug("Sending all metrics");
    for (MetricProvider mp : providers) {
        for (MetricDatum md : mp.getMetrics()) {
            logger.debug("Sending statistic {}", md.getMetricName());
            //PutMetricDataRequest request = new PutMetricDataRequest().withNamespace("geoserver").withMetricData(md);
            //cloudwatch.putMetricDataAsync(request);
            logger.debug("Sent statistic {}", md.getMetricName());
            System.out.println(md.getMetricName() + " value: " + md.getValue());
        }
    }
}

From source file:com.github.lpezet.antiope.metrics.aws.BlockingRequestBuilder.java

License:Open Source License

/**
 * Summarizes the given datum into the statistics of the respective unique metric.
 *///from  w ww.java2  s  .c  o  m
private void summarize(MetricDatum pDatum, Map<String, MetricDatum> pUniqueMetrics) {
    Double pValue = pDatum.getValue();
    if (pValue == null) {
        return;
    }
    List<Dimension> oDims = pDatum.getDimensions();
    Collections.sort(oDims, DimensionComparator.INSTANCE);
    String oMetricName = pDatum.getMetricName();
    String k = oMetricName + Jackson.toJsonString(oDims);
    MetricDatum oStatDatum = pUniqueMetrics.get(k);
    if (oStatDatum == null) {
        oStatDatum = new MetricDatum().withDimensions(pDatum.getDimensions()).withMetricName(oMetricName)
                .withUnit(pDatum.getUnit()).withStatisticValues(new StatisticSet().withMaximum(pValue)
                        .withMinimum(pValue).withSampleCount(0.0).withSum(0.0));
        pUniqueMetrics.put(k, oStatDatum);
    }
    StatisticSet oStat = oStatDatum.getStatisticValues();
    oStat.setSampleCount(oStat.getSampleCount() + 1.0);
    oStat.setSum(oStat.getSum() + pValue);
    if (pValue > oStat.getMaximum()) {
        oStat.setMaximum(pValue);
    } else if (pValue < oStat.getMinimum()) {
        oStat.setMinimum(pValue);
    }
}

From source file:com.github.lpezet.antiope.metrics.aws.BlockingRequestBuilder.java

License:Open Source License

/**
 * Return a collection of metrics almost the same as the input except with
 * all OS metrics removed./*w w  w .j  a v a2  s.  c o  m*/
 */
private Collection<MetricDatum> filterOSMetrics(Collection<MetricDatum> pData) {
    Collection<MetricDatum> oOutput = new ArrayList<MetricDatum>(pData.size());
    for (MetricDatum datum : pData) {
        if (!OS_METRIC_NAME.equals(datum.getMetricName()))
            oOutput.add(datum);
    }
    return oOutput;
}

From source file:com.github.lpezet.antiope.metrics.aws.BlockingRequestBuilder.java

License:Open Source License

/**
 * Returns a metric datum cloned from the given one.
 * Made package private only for testing purposes.
 *//* w  w  w  .  ja v a2s .c o m*/
final MetricDatum cloneMetricDatum(MetricDatum pMd) {
    return new MetricDatum().withDimensions(pMd.getDimensions()) // a new collection is created
            .withMetricName(pMd.getMetricName()).withStatisticValues(pMd.getStatisticValues())
            .withTimestamp(pMd.getTimestamp()).withUnit(pMd.getUnit()).withValue(pMd.getValue());
}

From source file:com.github.lpezet.antiope.metrics.aws.spi.MetricData.java

License:Open Source License

/**
 * Returns a new metric datum cloned from the given metric datum, but
 * replacing the dimensions with the newly specified ones.
 *//*from w w  w.  j av  a  2  s.co  m*/
public static MetricDatum newMetricDatum(MetricDatum pFrom, Dimension... pDimensions) {
    return new MetricDatum().withMetricName(pFrom.getMetricName()).withDimensions(pDimensions)
            .withUnit(pFrom.getUnit()).withValue(pFrom.getValue())
            .withStatisticValues(pFrom.getStatisticValues()).withTimestamp(pFrom.getTimestamp());
}