use of com.codahale.metrics.newrelic.util.TimeTracker 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.codahale.metrics.newrelic.util.TimeTracker in project dropwizard-metrics-newrelic by newrelic.
the class NewRelicReporterTest method setup.
@BeforeEach
void setup() {
commonAttributes = new Attributes().put("name", "the best").put("foo", false);
gaugeTransformer = mock(GaugeTransformer.class);
histogramTransformer = mock(HistogramTransformer.class);
counterTransformer = mock(CounterTransformer.class);
meterTransformer = mock(MeterTransformer.class);
timerTransformer = mock(TimerTransformer.class);
sender = mock(TelemetryClient.class);
timeTracker = mock(TimeTracker.class);
metricRegistry = new MetricRegistry();
}
use of com.codahale.metrics.newrelic.util.TimeTracker in project dropwizard-metrics-newrelic by newrelic.
the class NewRelicReporterBuilder method build.
public NewRelicReporter build() {
long rateFactor = rateUnit.toSeconds(1);
double durationFactor = durationUnit.toNanos(1);
Predicate<MetricAttribute> metricAttributePredicate = attr -> !disabledMetricAttributes.contains(attr);
TimeTracker timeTracker = new TimeTracker(Clock.defaultClock());
MeterTransformer meterTransformer = MeterTransformer.build(timeTracker, rateFactor, metricAttributePredicate, nameCustomizer, attributeCustomizer);
TimerTransformer timerTransformer = TimerTransformer.build(timeTracker, rateFactor, durationFactor, metricAttributePredicate, nameCustomizer, attributeCustomizer);
GaugeTransformer gaugeTransformer = new GaugeTransformer(nameCustomizer, attributeCustomizer);
CounterTransformer counterTransformer = new CounterTransformer(nameCustomizer, attributeCustomizer);
HistogramTransformer histogramTransformer = HistogramTransformer.build(timeTracker, nameCustomizer, attributeCustomizer);
return new NewRelicReporter(timeTracker, registry, name, filter, rateUnit, durationUnit, new TelemetryClient(metricBatchSender, null, null, null), commonAttributes, histogramTransformer, gaugeTransformer, counterTransformer, meterTransformer, timerTransformer, disabledMetricAttributes);
}
use of com.codahale.metrics.newrelic.util.TimeTracker 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);
}
Aggregations