MetricsCatcher { @Subscribe public void requestComplete(RemoveQuery<T> data) { registry.meter(prefix + ".requests-completed") .mark(); registry.counter(prefix + ".requests-completed-count") .inc(); ((InstantGauge) registry.gauge(prefix + ".requests-completed-interval-count", () -> new InstantGauge())) .increment(); if (this.configuration.isQueriesByType()) { RequestData<T> rd = data.getData(); registry.meter(queryEndName(rd)) .mark(); queries.complete(rd.getCorrelationId()); registry.counter(prefix + ".requests-active-" + rd.getType() + "-count") .dec(); ((InstantGauge) registry.gauge(prefix + ".requests-completed-" + rd.getType() + "-interval-count", () -> new InstantGauge())).increment(); } } @Autowired  MetricsCatcher(MetricRegistry registry, EventBus bus, Configuration configuration); @Subscribe void requestStart(AddQuery<T> data); @Subscribe void requestComplete(RemoveQuery<T> data); @Subscribe void requestStart(AddLabelledQuery<T> data); @Subscribe void requestComplete(RemoveLabelledQuery<T> data); @Subscribe void finished(SystemData data); @Subscribe void jobStarted(JobStartEvent data); @Subscribe void jobComplete(JobCompleteEvent data); @Subscribe void error(ErrorCode c); @Subscribe void error(ErrorEvent event); @Subscribe void genericEvent(GenericEvent event);  }
@Test public void queriesEndMeterInc() { catcher.requestComplete(new RemoveQuery( RequestData.builder() .correlationId("10") .type("test") .build())); assertThat(registry.meter(this.config.getPrefix() + ".request-end-test") .getMeanRate(), greaterThan(0.0)); }
@Test public void queriesCounterDec() { catcher.requestComplete(new RemoveQuery( RequestData.builder() .correlationId("10") .type("test") .build())); assertThat(registry.counter(this.config.getPrefix() + ".requests-active-test-count") .getCount(), equalTo(-1l)); }
@Test public void queriesIntervalCounterDec() { catcher.requestComplete(new RemoveQuery( RequestData.builder() .correlationId("10") .type("test") .build())); assertThat(registry.getGauges().size(), equalTo(2)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-interval-count").getValue(), equalTo(1l)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-test-interval-count").getValue(), equalTo(1l)); }