Search in sources :

Example 1 with TimeTracker

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);
}
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 2 with TimeTracker

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();
}
Also used : CounterTransformer(com.codahale.metrics.newrelic.transformer.CounterTransformer) HistogramTransformer(com.codahale.metrics.newrelic.transformer.HistogramTransformer) TimerTransformer(com.codahale.metrics.newrelic.transformer.TimerTransformer) TimeTracker(com.codahale.metrics.newrelic.util.TimeTracker) MetricRegistry(com.codahale.metrics.MetricRegistry) Attributes(com.newrelic.telemetry.Attributes) MeterTransformer(com.codahale.metrics.newrelic.transformer.MeterTransformer) TelemetryClient(com.newrelic.telemetry.TelemetryClient) GaugeTransformer(com.codahale.metrics.newrelic.transformer.GaugeTransformer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TimeTracker

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);
}
Also used : Clock(com.codahale.metrics.Clock) TimeTracker(com.codahale.metrics.newrelic.util.TimeTracker) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricAttributesCustomizer(com.codahale.metrics.newrelic.transformer.customizer.MetricAttributesCustomizer) TelemetryClient(com.newrelic.telemetry.TelemetryClient) TimerTransformer(com.codahale.metrics.newrelic.transformer.TimerTransformer) Predicate(java.util.function.Predicate) Attributes(com.newrelic.telemetry.Attributes) Set(java.util.Set) HistogramTransformer(com.codahale.metrics.newrelic.transformer.HistogramTransformer) TimeUnit(java.util.concurrent.TimeUnit) MetricAttribute(com.codahale.metrics.MetricAttribute) CounterTransformer(com.codahale.metrics.newrelic.transformer.CounterTransformer) MeterTransformer(com.codahale.metrics.newrelic.transformer.MeterTransformer) MetricNameCustomizer(com.codahale.metrics.newrelic.transformer.customizer.MetricNameCustomizer) MetricBatchSender(com.newrelic.telemetry.metrics.MetricBatchSender) MetricFilter(com.codahale.metrics.MetricFilter) GaugeTransformer(com.codahale.metrics.newrelic.transformer.GaugeTransformer) Collections(java.util.Collections) HistogramTransformer(com.codahale.metrics.newrelic.transformer.HistogramTransformer) TimerTransformer(com.codahale.metrics.newrelic.transformer.TimerTransformer) MeterTransformer(com.codahale.metrics.newrelic.transformer.MeterTransformer) MetricAttribute(com.codahale.metrics.MetricAttribute) TelemetryClient(com.newrelic.telemetry.TelemetryClient) CounterTransformer(com.codahale.metrics.newrelic.transformer.CounterTransformer) TimeTracker(com.codahale.metrics.newrelic.util.TimeTracker) GaugeTransformer(com.codahale.metrics.newrelic.transformer.GaugeTransformer)

Example 4 with TimeTracker

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

TimeTracker (com.codahale.metrics.newrelic.util.TimeTracker)4 Attributes (com.newrelic.telemetry.Attributes)4 Clock (com.codahale.metrics.Clock)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Snapshot (com.codahale.metrics.Snapshot)2 CounterTransformer (com.codahale.metrics.newrelic.transformer.CounterTransformer)2 GaugeTransformer (com.codahale.metrics.newrelic.transformer.GaugeTransformer)2 HistogramTransformer (com.codahale.metrics.newrelic.transformer.HistogramTransformer)2 MeterTransformer (com.codahale.metrics.newrelic.transformer.MeterTransformer)2 TimerTransformer (com.codahale.metrics.newrelic.transformer.TimerTransformer)2 TelemetryClient (com.newrelic.telemetry.TelemetryClient)2 Gauge (com.newrelic.telemetry.metrics.Gauge)2 Metric (com.newrelic.telemetry.metrics.Metric)2 Summary (com.newrelic.telemetry.metrics.Summary)2 Test (org.junit.jupiter.api.Test)2 Histogram (com.codahale.metrics.Histogram)1 MetricAttribute (com.codahale.metrics.MetricAttribute)1 MetricFilter (com.codahale.metrics.MetricFilter)1 Sampling (com.codahale.metrics.Sampling)1 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1