@Test
public void shouldReportHistogramSubsequentSnapshotValues_SumMaxMinValues() throws Exception {
CloudWatchReporter reporter = reporterBuilder.withStatisticSet().build();
final Histogram slidingWindowHistogram = new Histogram(new SlidingWindowReservoir(4));
metricRegistry.register("SlidingWindowHistogram", slidingWindowHistogram);
slidingWindowHistogram.update(1);
slidingWindowHistogram.update(2);
slidingWindowHistogram.update(30);
reporter.report();
final MetricDatum metricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);
assertThat(metricData.getStatisticValues().getMaximum().intValue()).isEqualTo(30);
assertThat(metricData.getStatisticValues().getMinimum().intValue()).isEqualTo(1);
assertThat(metricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(3);
assertThat(metricData.getStatisticValues().getSum().intValue()).isEqualTo(33);
assertThat(metricData.getUnit()).isEqualTo(None.toString());
slidingWindowHistogram.update(4);
slidingWindowHistogram.update(100);
slidingWindowHistogram.update(5);
slidingWindowHistogram.update(6);
reporter.report();
final MetricDatum secondMetricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);
assertThat(secondMetricData.getStatisticValues().getMaximum().intValue()).isEqualTo(100);
assertThat(secondMetricData.getStatisticValues().getMinimum().intValue()).isEqualTo(4);
assertThat(secondMetricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(4);
assertThat(secondMetricData.getStatisticValues().getSum().intValue()).isEqualTo(115);
assertThat(secondMetricData.getUnit()).isEqualTo(None.toString());
}
java类com.codahale.metrics.SlidingWindowReservoir的实例源码
CloudWatchReporterTest.java 文件源码
项目:codahale-aggregated-metrics-cloudwatch-reporter
阅读 36
收藏 0
点赞 0
评论 0
BasicMetricsContext.java 文件源码
项目:mongoose-base
阅读 35
收藏 0
点赞 0
评论 0
public BasicMetricsContext(
final String stepId, final IoType ioType, final IntSupplier actualConcurrencyGauge,
final int driverCount, final int concurrency, final int thresholdConcurrency,
final SizeInBytes itemDataSize, final int updateIntervalSec, final boolean stdOutColorFlag,
final boolean avgPersistFlag, final boolean sumPersistFlag,
final boolean perfDbResultsFileFlag
) {
this.stepId = stepId;
this.ioType = ioType;
this.actualConcurrencyGauge = actualConcurrencyGauge;
this.driverCount = driverCount;
this.concurrency = concurrency;
this.thresholdConcurrency = thresholdConcurrency > 0 ?
thresholdConcurrency : Integer.MAX_VALUE;
this.itemDataSize = itemDataSize;
this.stdOutColorFlag = stdOutColorFlag;
this.avgPersistFlag = avgPersistFlag;
this.sumPersistFlag = sumPersistFlag;
this.perfDbResultsFileFlag = perfDbResultsFileFlag;
this.outputPeriodMillis = TimeUnit.SECONDS.toMillis(updateIntervalSec);
respLatency = new Histogram(new SlidingWindowReservoir(DEFAULT_RESERVOIR_SIZE));
respLatSnapshot = respLatency.getSnapshot();
respLatencySum = new LongAdder();
reqDuration = new Histogram(new SlidingWindowReservoir(DEFAULT_RESERVOIR_SIZE));
reqDurSnapshot = reqDuration.getSnapshot();
actualConcurrency = new Histogram(new SlidingWindowReservoir(DEFAULT_RESERVOIR_SIZE));
actualConcurrencySnapshot = actualConcurrency.getSnapshot();
reqDurationSum = new LongAdder();
throughputSuccess = new CustomMeter(clock, updateIntervalSec);
throughputFail = new CustomMeter(clock, updateIntervalSec);
reqBytes = new CustomMeter(clock, updateIntervalSec);
ts = System.nanoTime();
}
SlidingWindowTimingStrategyTest.java 文件源码
项目:microbule
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void testCreateTimer() throws ReflectiveOperationException {
final SlidingWindowTimingStrategy strategy = new SlidingWindowTimingStrategy();
final Timer timer = strategy.createTimer(new MapConfig());
SlidingWindowReservoir reservoir = reservoir(timer);
assertNotNull(reservoir);
assertEquals("window", strategy.name());
}
DropwizardFlinkHistogramWrapperTest.java 文件源码
项目:flink
阅读 31
收藏 0
点赞 0
评论 0
/**
* Tests the histogram functionality of the DropwizardHistogramWrapper.
*/
@Test
public void testDropwizardHistogramWrapper() {
int size = 10;
DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(
new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
for (int i = 0; i < size; i++) {
histogramWrapper.update(i);
assertEquals(i + 1, histogramWrapper.getCount());
assertEquals(i, histogramWrapper.getStatistics().getMax());
assertEquals(0, histogramWrapper.getStatistics().getMin());
}
assertEquals(size, histogramWrapper.getStatistics().size());
assertEquals((size - 1) / 2.0, histogramWrapper.getStatistics().getQuantile(0.5), 0.001);
for (int i = size; i < 2 * size; i++) {
histogramWrapper.update(i);
assertEquals(i + 1, histogramWrapper.getCount());
assertEquals(i, histogramWrapper.getStatistics().getMax());
assertEquals(i + 1 - size, histogramWrapper.getStatistics().getMin());
}
assertEquals(size, histogramWrapper.getStatistics().size());
assertEquals(size + (size - 1) / 2.0, histogramWrapper.getStatistics().getQuantile(0.5), 0.001);
}
MetricManager.java 文件源码
项目:carbon-metrics
阅读 37
收藏 0
点赞 0
评论 0
/**
* Get reservoir implementation based on the reservoir type
*
* @return The {@link Reservoir} implementation
*/
private Reservoir getReservoir() {
// The Reservoir implementation is selected using a switch statement.
// The ReservoirType enum is a part of YAML configuration
// and foreign imports are not supported by Carbon Configuration Maven Plugin.
// Therefore, the Reservoir class cannot be imported and the Reservoir
// creation logic cannot be written inside ReservoirType enum.
switch (reservoirType) {
case EXPONENTIALLY_DECAYING:
return new ExponentiallyDecayingReservoir();
case UNIFORM:
return new UniformReservoir(reservoirParametersConfig.getSize());
case SLIDING_WINDOW:
return new SlidingWindowReservoir(reservoirParametersConfig.getSize());
case SLIDING_TIME_WINDOW:
return new SlidingTimeWindowReservoir(reservoirParametersConfig.getWindow(),
reservoirParametersConfig.getWindowUnit());
case HDR_HISTOGRAM:
Recorder recorder = new Recorder(reservoirParametersConfig.getNumberOfSignificantValueDigits());
if (reservoirParametersConfig.isResetOnSnapshot()) {
return new HdrHistogramResetOnSnapshotReservoir(recorder);
} else {
return new HdrHistogramReservoir(recorder);
}
default:
throw new RuntimeException("Invalid Reservoir Type");
}
}
SlidingWindowTimingStrategy.java 文件源码
项目:microbule
阅读 25
收藏 0
点赞 0
评论 0
@Override
public Timer createTimer(Config config) {
return new Timer(new SlidingWindowReservoir(config.integerValue(SIZE_PROP).orElse(DEFAULT_SIZE)));
}
DropwizardFlinkHistogramWrapperTest.java 文件源码
项目:flink
阅读 29
收藏 0
点赞 0
评论 0
/**
* Tests that the DropwizardHistogramWrapper reports correct dropwizard snapshots to the
* ScheduledReporter.
*/
@Test
public void testDropwizardHistogramWrapperReporting() throws Exception {
long reportingInterval = 1000;
long timeout = 30000;
int size = 10;
String histogramMetricName = "histogram";
Configuration config = new Configuration();
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "my_reporter." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestingReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "my_reporter." + ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, reportingInterval + " MILLISECONDS");
MetricRegistryImpl registry = null;
MetricRegistryConfiguration metricRegistryConfiguration = MetricRegistryConfiguration.fromConfiguration(config);
try {
registry = new MetricRegistryImpl(metricRegistryConfiguration);
DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(
new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
metricGroup.histogram(histogramMetricName, histogramWrapper);
String fullMetricName = metricGroup.getMetricIdentifier(histogramMetricName);
assertTrue(registry.getReporters().size() == 1);
MetricReporter reporter = registry.getReporters().get(0);
assertTrue(reporter instanceof TestingReporter);
TestingReporter testingReporter = (TestingReporter) reporter;
TestingScheduledReporter scheduledReporter = testingReporter.scheduledReporter;
// check that the metric has been registered
assertEquals(1, testingReporter.getMetrics().size());
for (int i = 0; i < size; i++) {
histogramWrapper.update(i);
}
Future<Snapshot> snapshotFuture = scheduledReporter.getNextHistogramSnapshot(fullMetricName);
Snapshot snapshot = snapshotFuture.get(timeout, TimeUnit.MILLISECONDS);
assertEquals(0, snapshot.getMin());
assertEquals((size - 1) / 2.0, snapshot.getMedian(), 0.001);
assertEquals(size - 1, snapshot.getMax());
assertEquals(size, snapshot.size());
registry.unregister(histogramWrapper, "histogram", metricGroup);
// check that the metric has been de-registered
assertEquals(0, testingReporter.getMetrics().size());
} finally {
if (registry != null) {
registry.shutdown();
}
}
}
Summary.java 文件源码
项目:prometheus-client
阅读 27
收藏 0
点赞 0
评论 0
/**
* Create this summary with a sliding window reservoir. This reservoir keeps a constant amount of the last
* measurements and is therefore memory-bound.
*
* @param size the number of measurements to save
*/
public SummaryBuilder withSlidingWindowReservoir(final int size) {
reservoirSupplier = () -> new SlidingWindowReservoir(size);
return SummaryBuilder.this;
}