Skip to content

Commit

Permalink
Add counter of rendered pages for issue #395
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomYdn committed Mar 27, 2020
1 parent 15b028b commit c3d8f9d
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import org.apache.wicket.MetaDataKey;
import org.apache.wicket.core.request.handler.IPageClassRequestHandler;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
Expand Down Expand Up @@ -40,6 +41,13 @@ public class OMetricsRequestCycleListener implements IRequestCycleListener {
.labelNames("ajax", "handler")
.create();

private static final Counter COUNTER_PAGES = Counter.build()
.namespace("wicket")
.name("pages")
.help("Total number of requests per page")
.labelNames("ajax", "handler")
.create();

private static final Histogram HISTOGRAM_REQUESTS = Histogram.build()
.namespace("wicket")
.name("requests")
Expand All @@ -53,6 +61,7 @@ private OMetricsRequestCycleListener() {
COUNTER_EXCEPTIONS.labels(Boolean.TRUE.toString()).inc(0);
COUNTER_EXCEPTIONS.labels(Boolean.FALSE.toString()).inc(0);
CollectorRegistry.defaultRegistry.register(COUNTER_EXECUTIONS);
CollectorRegistry.defaultRegistry.register(COUNTER_PAGES);
CollectorRegistry.defaultRegistry.register(HISTOGRAM_REQUESTS);
}

Expand All @@ -78,12 +87,18 @@ public IRequestHandler onException(RequestCycle cycle, Exception ex) {

@Override
public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler) {
COUNTER_EXECUTIONS.labels(Boolean.toString(((WebRequest)cycle.getRequest()).isAjax()),
String ajaxLabel = Boolean.toString(((WebRequest)cycle.getRequest()).isAjax());
COUNTER_EXECUTIONS.labels(ajaxLabel,
handler.getClass().getSimpleName()).inc();
if(handler instanceof IPageClassRequestHandler) {
COUNTER_PAGES.labels(ajaxLabel,
((IPageClassRequestHandler)handler).getPageClass().getSimpleName()).inc();
}
}

protected void onDestroy() {
CollectorRegistry.defaultRegistry.unregister(COUNTER_EXECUTIONS);
CollectorRegistry.defaultRegistry.unregister(COUNTER_PAGES);
CollectorRegistry.defaultRegistry.unregister(COUNTER_EXCEPTIONS);
CollectorRegistry.defaultRegistry.unregister(HISTOGRAM_REQUESTS);
}
Expand Down

0 comments on commit c3d8f9d

Please sign in to comment.