ThreadPoolMetrics implements MeterBinder { private Gauge.Builder<Supplier<Number>> gauge( final String name, final Supplier<Number> supplier) { return Gauge.builder(metricName + "." + name, supplier) .tags(defaultTags); } ThreadPoolMetrics(final ThreadPoolExecutor executor); ThreadPoolMetrics withMetricName(final String metricName); ThreadPoolMetrics withDefaultTags(final Tag... defaultTags); ThreadPoolMetrics withDefaultTags(final Iterable<Tag> defaultTags); @Override void bindTo(final MeterRegistry registry);  }
@Test void shouldMeasureInitial() { assertThat(gauge("http.client.threads.available").value(), is(0.0)); assertThat(gauge("http.client.threads.leased").value(), is(0.0)); assertThat(gauge("http.client.threads.total").value(), is(0.0)); assertThat(gauge("http.client.threads.min").value(), is(1.0)); assertThat(gauge("http.client.threads.max").value(), is(3.0)); assertThat(gauge("http.client.threads.queued").value(), is(0.0)); }
@Test void shouldMeasureIdle() throws InterruptedException { executor.execute(() -> {}); Thread.sleep(1000); assertThat(gauge("http.client.threads.available").value(), is(1.0)); assertThat(gauge("http.client.threads.leased").value(), is(0.0)); assertThat(gauge("http.client.threads.total").value(), is(1.0)); assertThat(gauge("http.client.threads.min").value(), is(1.0)); assertThat(gauge("http.client.threads.max").value(), is(3.0)); assertThat(gauge("http.client.threads.queued").value(), is(0.0)); }
@Test void shouldMeasureFull() { executor.execute(throwingRunnable(() -> Thread.sleep(1000))); executor.execute(throwingRunnable(() -> Thread.sleep(1000))); executor.execute(throwingRunnable(() -> Thread.sleep(1000))); executor.execute(throwingRunnable(() -> Thread.sleep(1000))); assertThat(gauge("http.client.threads.available").value(), is(0.0)); assertThat(gauge("http.client.threads.leased").value(), is(3.0)); assertThat(gauge("http.client.threads.total").value(), is(3.0)); assertThat(gauge("http.client.threads.min").value(), is(1.0)); assertThat(gauge("http.client.threads.max").value(), is(3.0)); assertThat(gauge("http.client.threads.queued").value(), is(1.0)); }