ParfaitReporter extends ScheduledReporter { @SuppressWarnings("PMD.ExcessiveParameterList") @Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { try { for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { publishMetric(entry.getKey(), entry.getValue()); } for (Map.Entry<String, Counter> entry : counters.entrySet()) { publishMetric(entry.getKey(), entry.getValue()); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { publishMetric(entry.getKey(), entry.getValue()); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { publishMetric(entry.getKey(), entry.getValue()); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { publishMetric(entry.getKey(), entry.getValue()); } } catch (RuntimeException ex) { LOGGER.error("An exception occurred publishing metrics to Parfait", ex); } } @SuppressWarnings("PMD.ExcessiveParameterList")  ParfaitReporter(MetricRegistry metricRegistry,
                           MonitorableRegistry monitorableRegistry,
                           MetricAdapterFactory metricAdapterFactory,
                           TimeUnit rateUnit,
                           TimeUnit durationUnit,
                           MetricFilter filter,
                           String metricNamePrefix); @SuppressWarnings("PMD.ExcessiveParameterList")  ParfaitReporter(MetricRegistry metricRegistry,
                           MonitorableRegistry monitorableRegistry,
                           DynamicMonitoringView dynamicMonitoringView,
                           MetricAdapterFactory metricAdapterFactory,
                           TimeUnit rateUnit,
                           TimeUnit durationUnit,
                           MetricFilter filter,
                           String prefix); @SuppressWarnings("PMD.ExcessiveParameterList") @Override void report(SortedMap<String, Gauge> gauges,
                       SortedMap<String, Counter> counters,
                       SortedMap<String, Histogram> histograms,
                       SortedMap<String, Meter> meters,
                       SortedMap<String, Timer> timers); @Override void start(long period, TimeUnit unit); @Override void stop();  }
@Test @SuppressWarnings("unchecked") public void shouldAttemptToPublishAllMetricsDuringReport() { when(metricAdapterFactory.createMetricAdapterFor(anyString(), any(Metric.class))).thenReturn(metricAdapter); parfaitReporter.report(generateGauges(), generateCounters(), generateHistogram(), generateMeters(), generateTimers()); verify(metricAdapterFactory).createMetricAdapterFor(METRIC_NAME_PREFIX + "." + TIMER_METRIC, timer); verify(metricAdapterFactory).createMetricAdapterFor(METRIC_NAME_PREFIX + "." + METER_METRIC, meter); verify(metricAdapterFactory).createMetricAdapterFor(METRIC_NAME_PREFIX + "." + HISTOGRAM_METRIC, histogram); verify(metricAdapterFactory).createMetricAdapterFor(METRIC_NAME_PREFIX + "." + COUNTER_METRIC, counter); verify(metricAdapterFactory).createMetricAdapterFor(METRIC_NAME_PREFIX + "." + GAUGE_METRIC, gauge); verify(monitorableRegistry, times(5)).register(monitorable); }
@Test @SuppressWarnings("unchecked") public void shouldOnlyPublishOnlyPreviouslyUnseenMetricsDuringReport() { when(metricAdapterFactory.createMetricAdapterFor(anyString(), any(Metric.class))).thenReturn(metricAdapter); parfaitReporter.report(generateGauges(), generateCounters(), generateHistogram(), generateMeters(), generateTimers()); parfaitReporter.report(generateGauges(), generateCounters(), generateHistogram(), generateMeters(), generateTimers()); verify(monitorableRegistry, times(5)).register(any(Monitorable.class)); SortedMap<String, Gauge> gauges = generateGauges(); gauges.put("newGaugeMetric", mock(Gauge.class)); parfaitReporter.report(gauges, generateCounters(), generateHistogram(), generateMeters(), generateTimers()); verify(monitorableRegistry, times(6)).register(monitorable); }