当前位置: 首页>>代码示例>>Java>>正文


Java MetricDatum类代码示例

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


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

示例1: send

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
@Override
public void send() throws IOException {
	final List<MetricDatum> datumList;
	synchronized (buffer) {
		datumList = new ArrayList<MetricDatum>(buffer);
		buffer.clear();
	}

	// note: Each PutMetricData request is limited to 40 KB in size for HTTP POST requests.
	final PutMetricDataRequest request = new PutMetricDataRequest()
			.withNamespace(cloudWatchNamespace).withMetricData(datumList);
	try {
		awsCloudWatch.putMetricData(request);
	} catch (final Exception e) {
		// pas catch (AmazonCloudWatchException) sinon ClassNotFoundException dans Jenkins par ex
		throw new IOException("Error connecting to AWS CloudWatch", e);
	}
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:19,代码来源:CloudWatch.java

示例2: flush

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的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: sendAggregatedData

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
private void sendAggregatedData() {

        // Grab all the current aggregated data, resetting
        // the aggregator to empty in the process
        List<MetricDatum> metricData = aggregator.flush();
        if(metricData.isEmpty()) {
            return;
        }

        // Send the data in batches to adhere to CloudWatch limitation on the
        // number of MetricDatum objects per request, see:
        // http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_limits.html
        int begin = 0;
        while(begin < metricData.size()) {
            int end = begin + BATCH_SIZE;

            sendData(metricData.subList(begin, Math.min(end, metricData.size())));

            begin = end;
        }

    }
 
开发者ID:awslabs,项目名称:swage,代码行数:23,代码来源:CloudWatchRecorder.java

示例4: makeDatum

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的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

示例5: processTimer

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
/**
 * The {@link Snapshot} values of {@link Timer} are reported as {@link StatisticSet} after conversion. The
 * conversion is done using the duration factor, which is deduced from the set duration unit.
 * <p>
 * Please note, the reported values submitted only if they show some data (greater than zero) in order to:
 * <p>
 * 1. save some money
 * 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
 * is submitted
 * <p>
 * If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
 *
 * @see Timer#getSnapshot
 * @see #getDurationUnit
 * @see #convertDuration(double)
 */
private void processTimer(final String metricName, final Timer timer, final List<MetricDatum> metricData) {
    final Snapshot snapshot = timer.getSnapshot();

    if (builder.withZeroValuesSubmission || snapshot.size() > 0) {
        for (final Percentile percentile : builder.percentiles) {
            final double convertedDuration = convertDuration(snapshot.getValue(percentile.getQuantile()));
            stageMetricDatum(true, metricName, convertedDuration, durationUnit, percentile.getDesc(), metricData);
        }
    }

    // prevent empty snapshot from causing InvalidParameterValueException
    if (snapshot.size() > 0) {
        final String formattedDuration = String.format(" [in-%s]", getDurationUnit());
        stageMetricDatum(builder.withArithmeticMean, metricName, convertDuration(snapshot.getMean()), durationUnit, DIMENSION_SNAPSHOT_MEAN + formattedDuration, metricData);
        stageMetricDatum(builder.withStdDev, metricName, convertDuration(snapshot.getStdDev()), durationUnit, DIMENSION_SNAPSHOT_STD_DEV + formattedDuration, metricData);
        stageMetricDatumWithConvertedSnapshot(builder.withStatisticSet, metricName, snapshot, durationUnit, metricData);
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:35,代码来源:CloudWatchReporter.java

示例6: processHistogram

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
/**
 * The {@link Snapshot} values of {@link Histogram} are reported as {@link StatisticSet} raw. In other words, the
 * conversion using the duration factor does NOT apply.
 * <p>
 * Please note, the reported values submitted only if they show some data (greater than zero) in order to:
 * <p>
 * 1. save some money
 * 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
 * is submitted
 * <p>
 * If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
 *
 * @see Histogram#getSnapshot
 */
private void processHistogram(final String metricName, final Histogram histogram, final List<MetricDatum> metricData) {
    final Snapshot snapshot = histogram.getSnapshot();

    if (builder.withZeroValuesSubmission || snapshot.size() > 0) {
        for (final Percentile percentile : builder.percentiles) {
            final double value = snapshot.getValue(percentile.getQuantile());
            stageMetricDatum(true, metricName, value, StandardUnit.None, percentile.getDesc(), metricData);
        }
    }

    // prevent empty snapshot from causing InvalidParameterValueException
    if (snapshot.size() > 0) {
        stageMetricDatum(builder.withArithmeticMean, metricName, snapshot.getMean(), StandardUnit.None, DIMENSION_SNAPSHOT_MEAN, metricData);
        stageMetricDatum(builder.withStdDev, metricName, snapshot.getStdDev(), StandardUnit.None, DIMENSION_SNAPSHOT_STD_DEV, metricData);
        stageMetricDatumWithRawSnapshot(builder.withStatisticSet, metricName, snapshot, StandardUnit.None, metricData);
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:32,代码来源:CloudWatchReporter.java

示例7: stageMetricDatum

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
/**
 * Please note, the reported values submitted only if they show some data (greater than zero) in order to:
 * <p>
 * 1. save some money
 * 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
 * is submitted
 * <p>
 * If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
 */
private void stageMetricDatum(final boolean metricConfigured,
                              final String metricName,
                              final double metricValue,
                              final StandardUnit standardUnit,
                              final String dimensionValue,
                              final List<MetricDatum> metricData) {
    // Only submit metrics that show some data, so let's save some money
    if (metricConfigured && (builder.withZeroValuesSubmission || metricValue > 0)) {
        final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
        dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(dimensionValue));

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

示例8: stageMetricDatumWithConvertedSnapshot

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的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

示例9: stageMetricDatumWithRawSnapshot

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的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

示例10: reportMetersCountersGaugesWithZeroValuesOnlyWhenConfigured

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
@Test
public void reportMetersCountersGaugesWithZeroValuesOnlyWhenConfigured() throws Exception {
    metricRegistry.register(ARBITRARY_GAUGE_NAME, (Gauge<Long>) () -> 0L);
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(0);
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc(0);
    metricRegistry.timer(ARBITRARY_TIMER_NAME).update(-1L, TimeUnit.NANOSECONDS);

    buildReportWithSleep(reporterBuilder
            .withArithmeticMean()
            .withOneMinuteMeanRate()
            .withFiveMinuteMeanRate()
            .withFifteenMinuteMeanRate()
            .withZeroValuesSubmission()
            .withMeanRate());

    verify(mockAmazonCloudWatchAsyncClient, times(1)).putMetricDataAsync(metricDataRequestCaptor.capture());

    final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
    final List<MetricDatum> metricData = putMetricDataRequest.getMetricData();
    for (final MetricDatum metricDatum : metricData) {
        assertThat(metricDatum.getValue()).isEqualTo(0.0);
    }
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:24,代码来源:CloudWatchReporterTest.java

示例11: shouldReportCounterValueDelta

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
@Test
public void shouldReportCounterValueDelta() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    final CloudWatchReporter cloudWatchReporter = reporterBuilder.build();

    cloudWatchReporter.report();
    MetricDatum metricDatum = firstMetricDatumFromCapturedRequest();
    assertThat(metricDatum.getValue().intValue()).isEqualTo(2);
    metricDataRequestCaptor.getAllValues().clear();

    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();

    cloudWatchReporter.report();
    metricDatum = firstMetricDatumFromCapturedRequest();
    assertThat(metricDatum.getValue().intValue()).isEqualTo(6);

    verify(mockAmazonCloudWatchAsyncClient, times(2)).putMetricDataAsync(any(PutMetricDataRequest.class));
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporterTest.java

示例12: shouldReportSnapshotValuesWithoutConversionWhenReportingHistogram

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
@Test
public void shouldReportSnapshotValuesWithoutConversionWhenReportingHistogram() throws Exception {
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(1);
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(2);
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(3);
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(30);
    reporterBuilder.withStatisticSet().build().report();

    final MetricDatum metricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);

    assertThat(metricData.getStatisticValues().getSum().intValue()).isEqualTo(36);
    assertThat(metricData.getStatisticValues().getMaximum().intValue()).isEqualTo(30);
    assertThat(metricData.getStatisticValues().getMinimum().intValue()).isEqualTo(1);
    assertThat(metricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(4);
    assertThat(metricData.getUnit()).isEqualTo(None.toString());
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:17,代码来源:CloudWatchReporterTest.java

示例13: metricDatumByDimensionFromCapturedRequest

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
private MetricDatum metricDatumByDimensionFromCapturedRequest(final String dimensionValue) {
    final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
    final List<MetricDatum> metricData = putMetricDataRequest.getMetricData();

    final Optional<MetricDatum> metricDatumOptional =
            metricData
                    .stream()
                    .filter(metricDatum -> metricDatum.getDimensions()
                            .contains(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(dimensionValue)))
                    .findFirst();

    if (metricDatumOptional.isPresent()) {
        return metricDatumOptional.get();
    }

    throw new IllegalStateException("Could not find MetricDatum for Dimension value: " + dimensionValue);
}
 
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:18,代码来源:CloudWatchReporterTest.java

示例14: runOneIteration

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
@Override
protected void runOneIteration() throws Exception {
    try {
        _cloudWatch.putMetricData(
                new PutMetricDataRequest()
                        .withNamespace(NAMESPACE)
                        .withMetricData(
                                new MetricDatum()
                                        .withTimestamp(new Date())
                                        .withMetricName(ACTIVE_AND_PENDING_SCANS)
                                        .withValue((double) (_activeScanCount + _pendingScanCount))
                                        .withUnit(StandardUnit.Count)
                                        .withDimensions(_dimensions)));
    } catch (AmazonClientException e) {
        _log.error("Failed to publish active and pending scans metric", e);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:CloudWatchScanCountListener.java

示例15: getMetricData

import com.amazonaws.services.cloudwatch.model.MetricDatum; //导入依赖的package包/类
private List<MetricDatum> getMetricData(Exchange exchange) {
    Object body = exchange.getIn().getBody();
    if (body instanceof List) {
        return CastUtils.cast((List<?>) body);
    }

    if (body instanceof MetricDatum) {
        return Arrays.asList((MetricDatum) body);
    }

    MetricDatum metricDatum = new MetricDatum()
            .withMetricName(determineName(exchange))
            .withValue(determineValue(exchange))
            .withUnit(determineUnit(exchange))
            .withTimestamp(determineTimestamp(exchange));
    setDimension(metricDatum, exchange);
    return Arrays.asList(metricDatum);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:CwProducer.java


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