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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations