Gitlab Community Edition Instance

Commit 0a95dbf7 authored by mhellka's avatar mhellka
Browse files

Added metrics for request rates and timings

parent d677cb93
......@@ -10,6 +10,10 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.codahale.metrics.Timer.Context;
import de.gwdg.cdstar.Utils;
import de.gwdg.cdstar.rest.CDStarRootModule;
import de.gwdg.cdstar.rest.RequestDispatcher;
......@@ -22,6 +26,7 @@ public class ApiRootServlet extends HttpServlet {
RestConfigImpl rootConfig;
RuntimeContext runtime;
private RequestDispatcher router;
private Timer timer;
private static final Logger log = LoggerFactory.getLogger(ApiRootServlet.class);
......@@ -41,6 +46,9 @@ public class ApiRootServlet extends HttpServlet {
if (log.isDebugEnabled())
log.debug("REST Configuration:\n{}", new RestConfigPrinter(rootConfig).render(true));
final MetricRegistry metrics = runtime.lookupRequired(MetricRegistry.class);
timer = metrics.timer("rest.rq");
super.init();
}
......@@ -49,7 +57,10 @@ public class ApiRootServlet extends HttpServlet {
protected void service(HttpServletRequest rq, HttpServletResponse rs) throws ServletException, IOException {
if (log.isDebugEnabled())
log.debug("Request: {} {} {}", rq.getRemoteAddr(), rq.getMethod(), rq.getPathInfo());
router.dispatch(new ServletRestContext(rq, rs));
final ServletRestContext ctx = new ServletRestContext(rq, rs);
final Context t1 = timer.time();
ctx.runAfterRequest(() -> t1.stop());
router.dispatch(ctx);
}
}
......@@ -3,11 +3,12 @@ package de.gwdg.cdstar.rest.v3;
import java.io.IOException;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Snapshot;
import de.gwdg.cdstar.Utils;
import de.gwdg.cdstar.rest.api.RestBlueprint;
import de.gwdg.cdstar.rest.api.RestConfig;
import de.gwdg.cdstar.rest.api.RestContext;
import de.gwdg.cdstar.rest.api.RestBlueprint;
import de.gwdg.cdstar.rest.utils.QueryHelper;
import de.gwdg.cdstar.rest.utils.SessionHelper;
import de.gwdg.cdstar.runtime.RuntimeContext;
......@@ -75,10 +76,18 @@ public class ServiceMetricsEndpoint implements RestBlueprint {
});
metrics.getTimers().forEach((name, c) -> {
result.setMetric(name + ".count", c.getCount());
result.setMetric(name + ".mean", c.getMeanRate());
result.setMetric(name + ".15m", c.getFiveMinuteRate());
result.setMetric(name + ".5m", c.getFiveMinuteRate());
result.setMetric(name + ".1m", c.getOneMinuteRate());
result.setMetric(name + ".rate", c.getMeanRate());
result.setMetric(name + ".rate15m", c.getFifteenMinuteRate());
result.setMetric(name + ".rate5m", c.getFiveMinuteRate());
result.setMetric(name + ".rate1m", c.getOneMinuteRate());
final Snapshot sample = c.getSnapshot();
result.setMetric(name + ".min", sample.getMin() / 1000000);
result.setMetric(name + ".max", sample.getMax() / 1000000);
result.setMetric(name + ".mean", sample.getMean() / 1000000);
result.setMetric(name + ".median", sample.getMedian() / 1000000);
result.setMetric(name + ".p75", sample.get75thPercentile() / 1000000);
result.setMetric(name + ".p95", sample.get95thPercentile() / 1000000);
result.setMetric(name + ".p99", sample.get99thPercentile() / 1000000);
});
return result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment