Search in sources :

Example 6 with Metric

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

the class CountingTransformerTest method testAfterRemoval.

@Test
public void testAfterRemoval() throws Exception {
    long now = System.currentTimeMillis();
    when(counting.getCount()).thenReturn(37L);
    when(timeTracker.getCurrentTime()).thenReturn(now);
    when(timeTracker.getPreviousTime()).thenReturn(now - 5000);
    Count expected = new Count("chocula", 37d, now - 5000, now, new Attributes());
    CountingTransformer countingTransformer = new CountingTransformer(timeTracker);
    Collection<Metric> firstResult = countingTransformer.transform("chocula", counting, baseAttributes);
    countingTransformer.remove("chocula");
    Collection<Metric> resultAfterClear = countingTransformer.transform("chocula", counting, baseAttributes);
    assertEquals(singleton(expected), firstResult);
    assertEquals(singleton(expected), resultAfterClear);
}
Also used : Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) Test(org.junit.jupiter.api.Test)

Example 7 with Metric

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

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

the class CounterTransformerTest method testSecondTimeSeen.

@Test
void testSecondTimeSeen() {
    Counter counter = new Counter();
    counter.inc(44);
    Gauge expected = new Gauge(COUNTER_NAME, 30, timestamp, EMPTY_ATTRIBUTES);
    CounterTransformer converter = new CounterTransformer(clock);
    converter.transform(COUNTER_NAME, counter);
    counter.dec(14);
    Collection<Metric> result = converter.transform(COUNTER_NAME, counter);
    assertEquals(singleton(expected), result);
}
Also used : Counter(com.codahale.metrics.Counter) Metric(com.newrelic.telemetry.metrics.Metric) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 9 with Metric

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

the class NewRelicReporter method report.

@Override
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
    List<Metric> metrics = Stream.of(transform(gauges, gaugeTransformer::transform), transform(histograms, histogramTransformer::transform), transform(counters, counterTransformer::transform), transform(meters, meterTransformer::transform), transform(timers, timerTransformer::transform)).flatMap(identity()).collect(toList());
    sender.sendBatch(new MetricBatch(metrics, commonAttributes));
    // set the previous harvest time in the tracker.
    timeTracker.tick();
}
Also used : MetricBatch(com.newrelic.telemetry.metrics.MetricBatch) Metric(com.newrelic.telemetry.metrics.Metric)

Example 10 with Metric

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

the class GaugeTransformer method transform.

@Override
public Collection<Metric> transform(String name, Gauge gauge) {
    String customizedName = nameCustomizer.customizeMetricName(name);
    Attributes customizedAttributes = attributeCustomizer.customizeMetricAttributes(name, gauge, new Attributes());
    long timestamp = clock.getTime();
    Object gaugeValue = gauge.getValue();
    if (gaugeValue == null) {
        LOG.debug("Ignoring gauge with null value. Gauge name: {}, Gauge attributes: {}", customizedName, customizedAttributes);
        return emptySet();
    }
    if (gaugeValue instanceof Number) {
        Metric metric = new com.newrelic.telemetry.metrics.Gauge(customizedName, ((Number) gaugeValue).doubleValue(), timestamp, customizedAttributes);
        return singleton(metric);
    }
    LOG.debug("Ignoring gauge [name: {}, Attributes: {}] with value of type {} (non-numeric gauges are unsupported)", customizedName, customizedAttributes, gaugeValue.getClass().getName());
    return emptySet();
}
Also used : Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Gauge(com.codahale.metrics.Gauge)

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