-
-
Save Rodolfocartas/b3398e2b8b758164a86b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package plugins; | |
| import play.PlayPlugin; | |
| import play.mvc.Http; | |
| import play.mvc.Http.Request; | |
| import play.mvc.Http.Response; | |
| import play.mvc.Router.Route; | |
| import play.vfs.VirtualFile; | |
| import util.MetricsUtil; | |
| public class MetricsPlugin extends PlayPlugin | |
| { | |
| @Override | |
| public boolean serveStatic(VirtualFile file, Request request, Response response) | |
| { | |
| String type = request.path.substring(request.path.lastIndexOf('.')+1); | |
| MetricsUtil.markMeter("static", type); | |
| return false; | |
| } | |
| @Override | |
| public void onRequestRouting(Route route) | |
| { | |
| Http.Request.current().args.put("route.action", route.action); | |
| Http.Request.current().args.put("route.method", route.method); | |
| MetricsUtil.markMeter("requests", route.action); | |
| MetricsUtil.markMeter("type", route.method); | |
| } | |
| @Override | |
| public void invocationFinally() | |
| { | |
| Http.Request request = Http.Request.current(); | |
| Http.Response response = Http.Response.current(); | |
| if (request == null || response == null) | |
| return; | |
| String action = (String) request.args.get("route.action"); | |
| String method = (String) request.args.get("route.method"); | |
| long requestProcessingTime = System.currentTimeMillis() - request.date.getTime(); | |
| int time = (int) requestProcessingTime; | |
| MetricsUtil.updateHistogram("histograms", "requesttime", time); | |
| if (action != null) | |
| MetricsUtil.updateHistogram("histograms.requesttime", action, time); | |
| if (method != null) | |
| MetricsUtil.updateHistogram("histograms.requesttime", method, time); | |
| if (request.action != null && response.out.size() > 0) | |
| { | |
| int size = response.out.size(); | |
| MetricsUtil.updateHistogram("histograms", "responsesize", size); | |
| if (action != null) | |
| MetricsUtil.updateHistogram("histograms.responsesize", action, size); | |
| if (method != null) | |
| MetricsUtil.updateHistogram("histograms.responsesize", method, size); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment