Search in sources :

Example 1 with Metric

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

the class GaugeTransformerTest method testDoubleGauge.

@Test
void testDoubleGauge() {
    // Given
    double value = 12345d;
    Gauge<Double> wizardGauge = () -> value;
    Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, value, timestamp, new Attributes());
    GaugeTransformer converter = new GaugeTransformer(clock);
    // When
    Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
    // Then
    assertEquals(singleton(expectedMetric), result);
}
Also used : Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) RatioGauge(com.codahale.metrics.RatioGauge) Gauge(com.codahale.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 2 with Metric

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

the class GaugeTransformerTest method testRatioGauge.

@Test
void testRatioGauge() {
    // Given
    Ratio ratio = Ratio.of(37, 31);
    RatioGauge wizardGauge = new RatioGauge() {

        @Override
        protected Ratio getRatio() {
            return ratio;
        }
    };
    Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, ratio.getValue(), timestamp, new Attributes());
    GaugeTransformer converter = new GaugeTransformer(clock);
    // When
    Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
    // Then
    assertEquals(singleton(expectedMetric), result);
}
Also used : RatioGauge(com.codahale.metrics.RatioGauge) Attributes(com.newrelic.telemetry.Attributes) Ratio(com.codahale.metrics.RatioGauge.Ratio) Metric(com.newrelic.telemetry.metrics.Metric) RatioGauge(com.codahale.metrics.RatioGauge) Gauge(com.codahale.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 3 with Metric

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

the class GaugeTransformerTest method testOtherNumericValue.

@Test
void testOtherNumericValue() {
    // Given
    BigDecimal value = new BigDecimal(12345d);
    Gauge<BigDecimal> wizardGauge = () -> value;
    Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, value.doubleValue(), timestamp, new Attributes());
    GaugeTransformer converter = new GaugeTransformer(clock);
    // When
    Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
    // Then
    assertEquals(singleton(expectedMetric), result);
}
Also used : Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) BigDecimal(java.math.BigDecimal) RatioGauge(com.codahale.metrics.RatioGauge) Gauge(com.codahale.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 4 with Metric

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

the class MeterTransformerTest method testTransformWithAttributeAndNameCustomization.

@Test
void testTransformWithAttributeAndNameCustomization() {
    Attributes otherAttributes = new Attributes().put("tag", "value").put("otherTag", "otherValue");
    Meter meter = new Meter();
    Metric expectedMetric = createExpectedGaugeMetric(otherAttributes);
    Count expectedCount = createExpectedCountMetric(otherAttributes);
    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, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
    Collection<Metric> result = testClass.transform(baseName + "[tag:value,otherTag:otherValue]", 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 5 with Metric

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

the class TimerTransformerTest method testTransformWithAttributeAndNameCustomization.

@Test
void testTransformWithAttributeAndNameCustomization() {
    Attributes otherTags = new Attributes().put("tag", "value").put("otherTag", "otherValue");
    long now = System.currentTimeMillis();
    Gauge result1 = new Gauge(baseName, 55d, now, otherTags);
    Gauge result2 = new Gauge(baseName, 999d, now, otherTags);
    Count expectedCount = createExpectedCountMetric(otherTags);
    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, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
    Collection<Metric> results = timerTransformer.transform(baseName + "[tag:value,otherTag:otherValue]", 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)

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