use of io.micrometer.core.instrument.Clock in project micrometer by micrometer-metrics.
the class MetricsClientHttpRequestInterceptor method intercept.
@Override
public ListenableFuture<ClientHttpResponse> intercept(HttpRequest request, byte[] body, AsyncClientHttpRequestExecution execution) throws IOException {
final String urlTemplate = urlTemplateHolder.get();
urlTemplateHolder.remove();
final Clock clock = meterRegistry.config().clock();
final long startTime = clock.monotonicTime();
ListenableFuture<ClientHttpResponse> future;
try {
future = execution.executeAsync(request, body);
} catch (IOException e) {
getTimeBuilder(urlTemplate, request, null).register(meterRegistry).record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS);
throw e;
}
future.addCallback(new ListenableFutureCallback<ClientHttpResponse>() {
@Override
public void onSuccess(final ClientHttpResponse response) {
getTimeBuilder(urlTemplate, request, response).register(meterRegistry).record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS);
}
@Override
public void onFailure(final Throwable ex) {
getTimeBuilder(urlTemplate, request, null).register(meterRegistry).record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS);
}
});
return future;
}
use of io.micrometer.core.instrument.Clock in project micrometer by micrometer-metrics.
the class MetricsClientHttpRequestInterceptor method intercept.
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
final String urlTemplate = urlTemplateHolder.get();
urlTemplateHolder.remove();
final Clock clock = meterRegistry.config().clock();
final long startTime = clock.monotonicTime();
ClientHttpResponse response = null;
try {
response = execution.execute(request, body);
return response;
} finally {
getTimeBuilder(urlTemplate, request, response).register(this.meterRegistry).record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS);
}
}
Aggregations