com.qmetric.spark.metrics.RouteTimerWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spark-metrics Show documentation
Show all versions of spark-metrics Show documentation
A library of Route decorators to add metrics to spark based applications and Routes to access the metrics
package com.qmetric.spark.metrics;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import spark.Request;
import spark.Response;
import spark.Route;
import static com.codahale.metrics.MetricRegistry.name;
public class RouteTimerWrapper extends Route
{
private static final String REGEX = "/";
private final Route route;
private final Timer timer;
public RouteTimerWrapper(final String path, final MetricRegistry metricRegistry, final Route route)
{
super(path);
this.route = route;
timer = metricRegistry.timer(name("timer", path.split(REGEX)));
}
@Override public Object handle(final Request request, final Response response)
{
final Timer.Context context = timer.time();
try {
return route.handle(request, response);
}finally {
context.stop();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy