Monitor Wicket page request using JAMon

02 Feb, 2008
Xebia Background Header Wave

For the Wicket webapplication I am currently working on, we build in JAMon for real time performance monitoring. As usual we intercept all calls to objects like Repositories and Services to monitor their performance. Because we use Spring we can easily intercept these Spring managed objects using Spring AOP. Besides these statistics we are also interested how long a certain page request takes. Since the Wicket components are not Spring managed we can not use Spring AOP. In this blog I´ll explain how you can put in JAMon monitoring for these page requests.

When monitoring these page requests I want to know which page was actually requested. I initially looked at the WicketFilter class as that is the entry point of your Wicket application. However I could not find a way to determine which page was actually requested there. So after a bit of investigation and confirmation from the wicket-user-group (very excellent and active user-group btw) it turned out the that the WebRequestCycle is the class we need to monitor. Wicket provides hooks which you need to override in your custom WebRequestCycle, namely onBeginRequest and onEndRequest. There is one tricky thing though: in the onBeginRequest the name of the requested Page is not yet available, so we need to store the start time of the request instead of the Monitor. In the onEndRequest we can determine which page is requested and can add the measured time to JAMon.
Here is the code of the custom WebRequestCycle:

public class JAMonMonitoredWebRequestCycle extends WebRequestCycle {
    static final String UNIT = "ms.";
    private long startTime;
    public JAMonMonitoredWebRequestCycle(WebApplication application, WebRequest request
                                                          , Response response) {
        super(application, request, response);
        this.startTime = 0;
    protected void onBeginRequest() {
        startTime = System.currentTimeMillis();
    protected void onEndRequest() {
    private void calculateDurationAndAddToMonitor() {
        if(startTime != 0) {
            Class pageClass = null;
            if(getWebResponse().isAjax() && getWebRequest().getPage() != null) {
                pageClass = getWebRequest().getPage().getClass();
            } else {
                pageClass = getResponsePageClass();
            if(pageClass != null) {
                MonitorFactory.add(pageClass.toString(), UNIT,
                                          System.currentTimeMillis() - startTime);

Get in touch with us to learn more about the subject and related solutions

Explore related posts