Search in sources :

Example 11 with Metric

use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.

the class HistogramTransformerTest method testTransformWithAttributeAndNameCustomization.

@Test
void testTransformWithAttributeAndNameCustomization() {
    Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
    String baseName = "history";
    String name = baseName + "[tag:value,otherTag:otherValue]";
    Attributes otherAttributes = new Attributes().put("tag", "value").put("otherTag", "otherValue");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 11000;
    Count expectedCount = new Count("countery", 12.6, startTime, endTime, otherAttributes);
    Metric expectedSamplingResult = new Gauge("samplery", 77.1, endTime, otherAttributes);
    Collection<Metric> expectedMetrics = Sets.newSet(expectedCount, expectedSamplingResult);
    when(counter.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedCount));
    when(sampler.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedSamplingResult));
    HistogramTransformer testClass = new HistogramTransformer(counter, sampler, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
    Collection<Metric> result = testClass.transform(name, histogram);
    assertEquals(expectedMetrics, result);
}
Also used : Histogram(com.codahale.metrics.Histogram) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 12 with Metric

use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.

the class HistogramTransformerTest method testTransform.

@Test
void testTransform() {
    Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 11000;
    Count expectedCount = new Count("countery", 12.6, startTime, endTime, new Attributes());
    Metric expectedSamplingResult = new Gauge("samplery", 77.1, endTime, new Attributes());
    Collection<Metric> expectedMetrics = Sets.newSet(expectedCount, expectedSamplingResult);
    when(counter.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedCount));
    when(sampler.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedSamplingResult));
    HistogramTransformer testClass = new HistogramTransformer(counter, sampler);
    Collection<Metric> result = testClass.transform("history", histogram);
    assertEquals(expectedMetrics, result);
}
Also used : Histogram(com.codahale.metrics.Histogram) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 13 with Metric

use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.

the class MeterTransformerTest method testTransform.

@Test
void testTransform() {
    Meter meter = new Meter();
    Metric expectedMetric = createExpectedGaugeMetric(new Attributes());
    Count expectedCount = createExpectedCountMetric(new Attributes());
    Collection<Metric> expectedMeters = Sets.newSet(expectedMetric, expectedCount);
    when(converter.transform(eq(baseName), eq(meter), notNull())).thenReturn(expectedMeters);
    when(countingTransformer.transform(eq(baseName), eq(meter), notNull())).thenReturn(singleton(expectedCount));
    MeterTransformer testClass = new MeterTransformer(converter, countingTransformer);
    Collection<Metric> result = testClass.transform(baseName, meter);
    assertEquals(expectedMeters, result);
}
Also used : Meter(com.codahale.metrics.Meter) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) Test(org.junit.jupiter.api.Test)

Example 14 with Metric

use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.

the class TimerTransformerTest method testTransform.

@Test
void testTransform() {
    long now = System.currentTimeMillis();
    Gauge result1 = new Gauge(baseName, 55d, now, new Attributes());
    Gauge result2 = new Gauge(baseName, 999d, now, new Attributes());
    Count expectedCount = createExpectedCountMetric(new Attributes());
    Timer timer = mock(Timer.class);
    SamplingTransformer samplingTransformer = mock(SamplingTransformer.class);
    MeteredTransformer meteredTransformer = mock(MeteredTransformer.class);
    CountingTransformer countingTransformer = mock(CountingTransformer.class);
    when(samplingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result1));
    when(meteredTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result2));
    when(countingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(expectedCount));
    TimerTransformer timerTransformer = new TimerTransformer(samplingTransformer, meteredTransformer, countingTransformer);
    Collection<Metric> results = timerTransformer.transform(baseName, timer);
    Collection<Metric> expected = Sets.newSet(result1, result2, expectedCount);
    assertEquals(expected, results);
}
Also used : SamplingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer) MeteredTransformer(com.codahale.metrics.newrelic.transformer.interfaces.MeteredTransformer) Timer(com.codahale.metrics.Timer) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) CountingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.CountingTransformer) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 15 with Metric

use of com.newrelic.telemetry.metrics.Metric 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

Metric (com.newrelic.telemetry.metrics.Metric)16 Test (org.junit.jupiter.api.Test)14 Attributes (com.newrelic.telemetry.Attributes)13 Gauge (com.newrelic.telemetry.metrics.Gauge)8 Count (com.newrelic.telemetry.metrics.Count)7 Gauge (com.codahale.metrics.Gauge)4 Histogram (com.codahale.metrics.Histogram)3 RatioGauge (com.codahale.metrics.RatioGauge)3 Counter (com.codahale.metrics.Counter)2 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Meter (com.codahale.metrics.Meter)2 Snapshot (com.codahale.metrics.Snapshot)2 Timer (com.codahale.metrics.Timer)2 CountingTransformer (com.codahale.metrics.newrelic.transformer.interfaces.CountingTransformer)2 MeteredTransformer (com.codahale.metrics.newrelic.transformer.interfaces.MeteredTransformer)2 SamplingTransformer (com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer)2 TimeTracker (com.codahale.metrics.newrelic.util.TimeTracker)2 Summary (com.newrelic.telemetry.metrics.Summary)2 Clock (com.codahale.metrics.Clock)1 Ratio (com.codahale.metrics.RatioGauge.Ratio)1