DropWizardMetricsRegistry extends MetricRegistry { @Override public Counter counter(Id id) { if (overSize(id)) { return NoopRegistry.INSTANCE.counter(id); } final String name = toMetricName(id); return new DwMetricsCounter(clock(), id, impl.counter(name)); } DropWizardMetricsRegistry();  DropWizardMetricsRegistry(Clock clock, com.codahale.metrics.MetricRegistry impl);  DropWizardMetricsRegistry(Clock clock, com.codahale.metrics.MetricRegistry impl,
                                     MetricConfig metricConfig); @Override Gauge<T> gauge(Id id, Gauge<T> gauge); @Override Counter counter(Id id); @Override DistributionSummary distributionSummary(Id id); @Override Timer timer(Id id); @Override void register(final Metric metric); @Override void removeMetric(Id id); @Override void propagate(String msg, Throwable t); @Override MixinMetric mixinMetric(Id id); @Override void registerExtendedMetrics(); @Override Info info(Id id, Y info); @Override X get(Id id); @Override Iterator<Metric> iterator(); boolean overSize(Id id);  }
@Test public void testDropwizardOverMaxCount() { MetricRegistry reg = new MetricRegistry(); LookoutConfig lookoutConfig = new LookoutConfig(); lookoutConfig.setProperty(LookoutConfig.LOOKOUT_MAX_METRICS_NUMBER, 1); DropWizardMetricsRegistry dwreg = new DropWizardMetricsRegistry(Clock.SYSTEM, reg, lookoutConfig); Counter counter1 = dwreg.counter(dwreg.createId("a.b")); Counter counter2 = dwreg.counter(dwreg.createId("a.b.c")); System.out.println(counter2.getClass().getCanonicalName()); Assert.assertTrue(counter2.getClass().getCanonicalName().contains("NoopCounter")); }
@Test public void testDropwizardCount() { MetricRegistry reg = new MetricRegistry(); DropWizardMetricsRegistry dwreg = new DropWizardMetricsRegistry(Clock.SYSTEM, reg); Counter counter1 = dwreg.counter(dwreg.createId("a.b.c")); counter1.inc(5); com.codahale.metrics.Counter counter2 = reg.counter("a.b.c"); System.out.println(counter2.getCount()); Assert.assertEquals(5, counter2.getCount()); }