use of com.newrelic.telemetry.metrics.Summary in project dropwizard-metrics-newrelic by newrelic.
the class SamplingTransformerTest method testBasicSampling.
@Test
void testBasicSampling() {
Sampling sampling = buildSampling();
Snapshot snapshot = sampling.getSnapshot();
Collection<Metric> expected = Sets.newSet(new Summary("blobby", 6, 23, .3, .5, now, now, new Attributes()), new Gauge("blobby.percentiles", snapshot.getMedian() / 10d, now, percentileAttributes(50.0).put("commonName", "median")), new Gauge("blobby.percentiles", 0.1d * snapshot.get75thPercentile(), now, percentileAttributes(75.0)), new Gauge("blobby.percentiles", 0.1d * snapshot.get95thPercentile(), now, percentileAttributes(95.0)), new Gauge("blobby.percentiles", 0.1d * snapshot.get98thPercentile(), now, percentileAttributes(98.0)), new Gauge("blobby.percentiles", 0.1d * snapshot.get99thPercentile(), now, percentileAttributes(99.0)), new Gauge("blobby.percentiles", 0.1d * snapshot.get999thPercentile(), now, percentileAttributes(99.9)));
Clock clock = mock(Clock.class);
when(clock.getTime()).thenReturn(now);
SamplingTransformer testClass = new SamplingTransformer(new TimeTracker(clock), 10);
Collection<Metric> result = testClass.transform("blobby", sampling, baseAttributes);
assertEquals(expected, result);
}
use of com.newrelic.telemetry.metrics.Summary in project dropwizard-metrics-newrelic by newrelic.
the class SamplingTransformer method transform.
@Override
public Collection<Metric> transform(String name, Sampling sampling, Supplier<Attributes> baseAttributes) {
Snapshot snapshot = sampling.getSnapshot();
long now = timeTracker.getCurrentTime();
long previousTime = timeTracker.getPreviousTime();
Summary summary = new Summary(name, snapshot.size(), calculateSum(snapshot), scaleLongValue(snapshot.getMin()), scaleLongValue(snapshot.getMax()), previousTime, now, baseAttributes.get());
Gauge median = new Gauge(name + ".percentiles", scaleDoubleValue(snapshot.getMedian()), now, buildAttributes(baseAttributes.get(), .50).put("commonName", "median"));
Stream<Gauge> gauges = Stream.of(0.75d, 0.95d, 0.98d, 0.99d, 0.999d).map(percentile -> new Gauge(name + ".percentiles", scaleDoubleValue(snapshot.getValue(percentile)), now, buildAttributes(baseAttributes.get(), percentile)));
return concat(Stream.of(median, summary), gauges).collect(toSet());
}
use of com.newrelic.telemetry.metrics.Summary in project dropwizard-metrics-newrelic by newrelic.
the class SamplingTransformerTest method testMultipleVisitsGetYouSomeState.
@Test
void testMultipleVisitsGetYouSomeState() {
Histogram histogram = new Histogram(new SlidingWindowReservoir(10));
recordSomeData(histogram);
long later = now + 5000;
TimeTracker timeTracker = mock(TimeTracker.class);
when(timeTracker.getCurrentTime()).thenReturn(later);
when(timeTracker.getPreviousTime()).thenReturn(now);
SamplingTransformer testClass = new SamplingTransformer(timeTracker, 0.10d);
testClass.transform("hollerMonkey", histogram, baseAttributes);
recordSomeData(histogram);
Collection<Metric> result = testClass.transform("hollerMonkey", histogram, baseAttributes);
Snapshot snapshot = histogram.getSnapshot();
Collection<Metric> expected = Sets.newSet(new Summary("hollerMonkey", 10, 40, 3 * 10, 5 * 10, now, later, new Attributes()), new Gauge("hollerMonkey.percentiles", snapshot.getMedian() * 10, later, percentileAttributes(50.0).put("commonName", "median")), new Gauge("hollerMonkey.percentiles", snapshot.get75thPercentile() * 10, later, percentileAttributes(75.0)), new Gauge("hollerMonkey.percentiles", snapshot.get95thPercentile() * 10, later, percentileAttributes(95.0)), new Gauge("hollerMonkey.percentiles", snapshot.get98thPercentile() * 10, later, percentileAttributes(98.0)), new Gauge("hollerMonkey.percentiles", snapshot.get99thPercentile() * 10, later, percentileAttributes(99.0)), new Gauge("hollerMonkey.percentiles", snapshot.get999thPercentile() * 10, later, percentileAttributes(99.9)));
assertEquals(expected, result);
}
Aggregations