Search in sources :

Example 1 with Summary

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);
}
Also used : Snapshot(com.codahale.metrics.Snapshot) TimeTracker(com.codahale.metrics.newrelic.util.TimeTracker) Attributes(com.newrelic.telemetry.Attributes) Summary(com.newrelic.telemetry.metrics.Summary) Metric(com.newrelic.telemetry.metrics.Metric) Sampling(com.codahale.metrics.Sampling) Clock(com.codahale.metrics.Clock) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 2 with Summary

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());
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Summary(com.newrelic.telemetry.metrics.Summary) Gauge(com.newrelic.telemetry.metrics.Gauge)

Example 3 with Summary

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);
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) TimeTracker(com.codahale.metrics.newrelic.util.TimeTracker) Attributes(com.newrelic.telemetry.Attributes) Summary(com.newrelic.telemetry.metrics.Summary) Metric(com.newrelic.telemetry.metrics.Metric) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)3 Gauge (com.newrelic.telemetry.metrics.Gauge)3 Summary (com.newrelic.telemetry.metrics.Summary)3 TimeTracker (com.codahale.metrics.newrelic.util.TimeTracker)2 Attributes (com.newrelic.telemetry.Attributes)2 Metric (com.newrelic.telemetry.metrics.Metric)2 Test (org.junit.jupiter.api.Test)2 Clock (com.codahale.metrics.Clock)1 Histogram (com.codahale.metrics.Histogram)1 Sampling (com.codahale.metrics.Sampling)1 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1