• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java StatisticSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.StatisticSet的典型用法代码示例。如果您正苦于以下问题:Java StatisticSet类的具体用法?Java StatisticSet怎么用?Java StatisticSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StatisticSet类属于com.amazonaws.services.cloudwatch.model包,在下文中一共展示了StatisticSet类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: add

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
/**
 * Add a metric event to be aggregated.
 * Events with the same name, unit, and dimensions will have their values
 * aggregated into {@link StatisticSet}s, with the aggregated data
 * available via {@link #flush}.
 *
 * @param context Metric context to use for dimension information
 * @param name Metric name
 * @param value Recorded value for the metric event
 * @param unit Unit for interpreting the value
 */
public void add(
        final TypedMap context,
        final Metric name,
        final double value,
        final StandardUnit unit)
{
    //TODO: avoid doing this every time for a context - caching, or?
    List<Dimension> dimensions = dimensionMapper.getDimensions(name, context);

    DatumKey key = new DatumKey(name.toString(), unit, dimensions);
    statisticsMap.merge(
            key,
            new StatisticSet()
                    .withMaximum(value)
                    .withMinimum(value)
                    .withSampleCount(1D)
                    .withSum(value),
            MetricDataAggregator::sum);
}
 
开发者ID:awslabs,项目名称:swage,代码行数:31,代码来源:MetricDataAggregator.java


示例2: flush

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
/**
 * Flush all the current aggregated MetricDatum and return as a list.
 * This is safe to call concurrently with {@link #add}.
 * All data added prior to a flush call will be included in the returned aggregate.
 * Any data added after the flush call returns will be included in a subsequent flush.
 * Data added while a flush call is processing may be included in the current flush
 * or a subsequent flush, but will not be included twice.
 *
 * The timestamp on the aggregated data will be the time it was flushed,
 * not the time of any of the original metric events.
 *
 * @return list of all data aggregated since the last flush
 */
public List<MetricDatum> flush() {
    if (statisticsMap.size() == 0) {
        return Collections.emptyList();
    }

    // Capture all the current metrics, as represented by the set of keys
    // at this time in the statisticsMap.
    // Note that this iterates over the key set of the underlying map, and
    // removes keys from the map at the same time. It is possible keys may
    // be added during this iteration, or data for keys modified between
    // a key being chosen for iteration and being removed from the map.
    // This is ok.  Any new keys will be picked up on subsequent flushes.
    //TODO: use two maps and swap between, to ensure 'perfect' segmentation?
    List<MetricDatum> metricData = new ArrayList<>();
    for (DatumKey key : statisticsMap.keySet()) {
        StatisticSet value = statisticsMap.remove(key);
        //TODO: better to have no timestamp at all?
        MetricDatum metricDatum = key.getDatum().withTimestamp(Date.from(Instant.now()))
                                                .withStatisticValues(value);
        metricData.add(metricDatum);
    }

    return metricData;
}
 
开发者ID:awslabs,项目名称:swage,代码行数:38,代码来源:MetricDataAggregator.java


示例3: makeDatum

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
private MetricDatum makeDatum(
        final String id,
        final String name,
        final double sum,
        final double min,
        final double max,
        final int count,
        final StandardUnit unit)
{
    MetricDatum md = new MetricDatum().withMetricName(name).withUnit(unit);

    final StatisticSet statSet = new StatisticSet()
            .withSampleCount(Double.valueOf(count))
            .withSum(sum)
            .withMinimum(min)
            .withMaximum(max);
    md.setStatisticValues(statSet);

    List<Dimension> dimensions = new ArrayList<>(1);
    Dimension trace = new Dimension().withName(ContextData.ID.name).withValue(id);

    dimensions.add(trace);
    md.setDimensions(dimensions);

    return md;
}
 
开发者ID:awslabs,项目名称:swage,代码行数:27,代码来源:CloudWatchRecorderTest.java


示例4: stageMetricDatumWithConvertedSnapshot

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
private void stageMetricDatumWithConvertedSnapshot(final boolean metricConfigured,
                                                   final String metricName,
                                                   final Snapshot snapshot,
                                                   final StandardUnit standardUnit,
                                                   final List<MetricDatum> metricData) {
    if (metricConfigured) {
        double scaledSum = convertDuration(LongStream.of(snapshot.getValues()).sum());
        final StatisticSet statisticSet = new StatisticSet()
                .withSum(scaledSum)
                .withSampleCount((double) snapshot.size())
                .withMinimum(convertDuration(snapshot.getMin()))
                .withMaximum(convertDuration(snapshot.getMax()));

        final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
        dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));

        metricData.add(new MetricDatum()
                .withTimestamp(new Date(builder.clock.getTime()))
                .withMetricName(metricName)
                .withDimensions(dimensions)
                .withStatisticValues(statisticSet)
                .withUnit(standardUnit));
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java


示例5: stageMetricDatumWithRawSnapshot

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
private void stageMetricDatumWithRawSnapshot(final boolean metricConfigured,
                                             final String metricName,
                                             final Snapshot snapshot,
                                             final StandardUnit standardUnit,
                                             final List<MetricDatum> metricData) {
    if (metricConfigured) {
        double total = LongStream.of(snapshot.getValues()).sum();
        final StatisticSet statisticSet = new StatisticSet()
                .withSum(total)
                .withSampleCount((double) snapshot.size())
                .withMinimum((double) snapshot.getMin())
                .withMaximum((double) snapshot.getMax());

        final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
        dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));

        metricData.add(new MetricDatum()
                .withTimestamp(new Date(builder.clock.getTime()))
                .withMetricName(metricName)
                .withDimensions(dimensions)
                .withStatisticValues(statisticSet)
                .withUnit(standardUnit));
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java


示例6: reportSampling

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
/**
 * @param rescale the submitted sum by this multiplier. 1.0 is the identity (no rescale).
 */
void reportSampling(Map.Entry<String, ? extends Sampling> entry, String typeDimValue, double rescale, List<MetricDatum> data) {
    Sampling metric = entry.getValue();
    Snapshot snapshot = metric.getSnapshot();
    double scaledSum = sum(snapshot.getValues()) * rescale;
    final StatisticSet statisticSet = new StatisticSet()
            .withSum(scaledSum)
            .withSampleCount((double) snapshot.size())
            .withMinimum((double) snapshot.getMin() * rescale)
            .withMaximum((double) snapshot.getMax() * rescale);

    DemuxedKey key = new DemuxedKey(appendGlobalDimensions(entry.getKey()));
    Iterables.addAll(data, key.newDatums(typeDimName, typeDimValue, new Function<MetricDatum, MetricDatum>() {
        @Override
        public MetricDatum apply(MetricDatum datum) {
            return datum.withStatisticValues(statisticSet);
        }
    }));
}
 
开发者ID:blacklocus,项目名称:metrics-cloudwatch,代码行数:22,代码来源:CloudWatchReporter.java


示例7: sum

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
private static StatisticSet sum( StatisticSet v1, StatisticSet v2 ) {
    //TODO: reuse one of the passed sets, and pollute a MetricDatum?
    StatisticSet stats = new StatisticSet();

    stats.setMaximum(Math.max(v1.getMaximum(), v2.getMaximum()));
    stats.setMinimum(Math.min(v1.getMinimum(), v2.getMinimum()));
    stats.setSampleCount(v1.getSampleCount() + v2.getSampleCount());
    stats.setSum(v1.getSum() + v2.getSum());

    return stats;
}
 
开发者ID:awslabs,项目名称:swage,代码行数:12,代码来源:MetricDataAggregator.java


示例8: single

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
@Test
public void single() throws Exception {
    final DimensionMapper mapper = new DimensionMapper.Builder()
            .addGlobalDimension(ContextData.ID)
            .build();

    final Metric name = Metric.define("SomeMetric");
    final double value = 3.14;
    final StandardUnit unit = StandardUnit.Terabits;

    final TypedMap context = ContextData.withId(UUID.randomUUID().toString()).build();

    MetricDataAggregator aggregator = new MetricDataAggregator(mapper);
    aggregator.add(context, name, value, unit);

    List<MetricDatum> ags = aggregator.flush();

    assertEquals("One metric datum should aggregate to one entry", 1, ags.size());
    assertEquals("Metric datum has wrong name", name.toString(), ags.get(0).getMetricName());
    assertEquals("Metric datum has wrong unit", unit.toString(), ags.get(0).getUnit());

    StatisticSet stats = ags.get(0).getStatisticValues();
    assertEquals("Metric datum has wrong stats value", Double.valueOf(value), stats.getSum());
    assertEquals("Metric datum has wrong stats value", Double.valueOf(value), stats.getMinimum());
    assertEquals("Metric datum has wrong stats value", Double.valueOf(value), stats.getMaximum());
    assertEquals("Metric datum has wrong stats count", Double.valueOf(1), stats.getSampleCount());

    assertTrue("Flush with no data was non-empty", aggregator.flush().isEmpty());
}
 
开发者ID:awslabs,项目名称:swage,代码行数:30,代码来源:MetricDataAggregatorTest.java


示例9: reportTimer

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
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 {
        // 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));
    }
}
 
开发者ID:basis-technology-corp,项目名称:metrics-cloudwatch-reporter,代码行数:38,代码来源:CloudWatchReporter.java


示例10: reportHistogram

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
private void reportHistogram(Collection<MetricDatum> data, Map.Entry<String, Histogram> meh) {
    Snapshot snapshot = meh.getValue().getSnapshot();

    if (reportAggregates) {
        String key = meh.getKey();
        reportSnapshot(data, snapshot, key);
    } else {
        // if no data, don't bother Amazon with it.
        if (snapshot.size() == 0) {
            return;
        }
        double sum = 0;
        for (double val : snapshot.getValues()) {
            sum += val;
        }
        StatisticSet stats = new StatisticSet().withMaximum((double) snapshot.getMax())
                .withMinimum((double) snapshot.getMin())
                .withSum(sum)
                .withSampleCount((double) snapshot.getValues().length);
        if (LOG.isDebugEnabled()) {
            LOG.debug("histogram {}: {}", meh.getKey(), stats);
        }
        data.add(new MetricDatum().withMetricName(meh.getKey())
                .withDimensions(dimensions)
                .withStatisticValues(stats));
    }
}
 
开发者ID:basis-technology-corp,项目名称:metrics-cloudwatch-reporter,代码行数:28,代码来源:CloudWatchReporter.java


示例11: run

import com.amazonaws.services.cloudwatch.model.StatisticSet; //导入依赖的package包/类
/**
 * Collect the aggregated values (min, max, count, sum) into a
 * StatisticSet and send the data to Cloud Watch
 */
@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);
}
 
开发者ID:web-online,项目名称:cloudwatch-tomcat-valve,代码行数:36,代码来源:ElapsedTimeAggregator.java



注:本文中的com.amazonaws.services.cloudwatch.model.StatisticSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CheckedAllocationException类代码示例发布时间:2022-05-23
下一篇:
Java VisibleForTesting类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap