Example usage for com.amazonaws.services.cloudwatch.model StandardUnit Microseconds

List of usage examples for com.amazonaws.services.cloudwatch.model StandardUnit Microseconds

Introduction

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

Prototype

StandardUnit Microseconds

To view the source code for com.amazonaws.services.cloudwatch.model StandardUnit Microseconds.

Click Source Link

Usage

From source file:com.basistech.metrics.CloudWatchReporter.java

License:Open Source License

private void reportTimer(String key, Collection<MetricDatum> data, Map.Entry<String, Timer> met) {
    Timer timer = met.getValue();
    Snapshot snapshot = timer.getSnapshot();
    if (reportAggregates) {
        reportAggregate(key, data, "count", null, timer.getCount());
        reportAggregate(key, data, "rate", "1minute", timer.getOneMinuteRate());
        reportAggregate(key, data, "rate", "5minute", timer.getFiveMinuteRate());
        reportAggregate(key, data, "rate", "15minute", timer.getFifteenMinuteRate());
        reportAggregate(key, data, "rate", "mean", timer.getMeanRate());
        reportSnapshot(data, snapshot, key);
    } else {/*from  w  w w  .jav a2  s .c  o  m*/
        // if no data, don't bother Amazon with it.
        if (snapshot.size() == 0) {
            return;
        }
        double sum = 0;
        for (double val : snapshot.getValues()) {
            sum += val;
        }
        // Metrics works in Nanoseconds, which is not one of Amazon's favorites.
        double max = (double) TimeUnit.NANOSECONDS.toMicros(snapshot.getMax());
        double min = (double) TimeUnit.NANOSECONDS.toMicros(snapshot.getMin());
        double sumMicros = TimeUnit.NANOSECONDS.toMicros((long) sum);
        StatisticSet stats = new StatisticSet().withMaximum(max).withMinimum(min).withSum(sumMicros)
                .withSampleCount((double) snapshot.getValues().length);
        if (LOG.isDebugEnabled()) {
            LOG.debug("timer {}: {}", met.getKey(), stats);
        }
        data.add(new MetricDatum().withMetricName(met.getKey()).withDimensions(dimensions)
                .withStatisticValues(stats).withUnit(StandardUnit.Microseconds));
    }
}