io.vertx.ext.dropwizard.impl.DropwizardClientMetrics Maven / Gradle / Ivy
package io.vertx.ext.dropwizard.impl;
import com.codahale.metrics.Counter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import io.vertx.core.spi.metrics.ClientMetrics;
import java.util.concurrent.TimeUnit;
/**
* @author Julien Viet
*/
public class DropwizardClientMetrics extends AbstractMetrics implements ClientMetrics {
final VertxMetricsImpl vertxMetrics;
final Timer requests;
final Timer ttfb;
final Counter inUse;
final int count;
public DropwizardClientMetrics(VertxMetricsImpl vertxMetrics, MetricRegistry registry, String baseName, int count) {
super(registry, baseName);
this.vertxMetrics = vertxMetrics;
this.requests = timer("requests");
this.ttfb = timer("ttfb");
this.inUse = counter("in-use");
this.count = count;
}
private DropwizardClientMetrics(DropwizardClientMetrics that, int count) {
super(that.registry, that.baseName);
this.vertxMetrics = that.vertxMetrics;
this.requests = that.requests;
this.ttfb = that.ttfb;
this.inUse = that.inUse;
this.count = count;
}
DropwizardClientMetrics inc() {
return new DropwizardClientMetrics<>(this, count + 1);
}
DropwizardClientMetrics dec() {
return new DropwizardClientMetrics<>(this, count - 1);
}
@Override
public RequestMetric requestBegin(String uri, Req request) {
inUse.inc();
RequestMetric metric = new RequestMetric();
metric.requestBegin = System.nanoTime();
return metric;
}
@Override
public void requestEnd(RequestMetric metric) {
metric.requestEnd = System.nanoTime();
}
@Override
public void responseBegin(RequestMetric requestMetric, Resp response) {
long waitTime = System.nanoTime() - requestMetric.requestEnd;
ttfb.update(waitTime, TimeUnit.NANOSECONDS);
}
@Override
public void requestReset(RequestMetric requestMetric) {
inUse.inc();
}
@Override
public void responseEnd(RequestMetric requestMetric) {
long duration = System.nanoTime() - requestMetric.requestBegin;
inUse.dec();
requests.update(duration, TimeUnit.NANOSECONDS);
}
@Override
public void close() {
vertxMetrics.closed(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy