• Home
  • RSS Feed
  • Log in


Monitor Wicket page request using JAMon
Posted by Lars Vonk in the late evening: February 2nd, 2008

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;
    }

    @Override
    protected void onBeginRequest() {
        super.onBeginRequest();
        startTime = System.currentTimeMillis();
    }

    @Override
    protected void onEndRequest() {
        super.onEndRequest();
        calculateDurationAndAddToMonitor();
    }

    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);
            }
        }
    }

}
Share

Filed under Java | 2 Comments »



2 Responses to “Monitor Wicket page request using JAMon”



    Erik van Oosten Says:
    Posted at: September 26, 2008 at 4:47 pm

    Nice!
    Just one small remark. With this little change you also measure the duration of super.onBeginRequest:

    @Override
    protected void onBeginRequest() {
    super.onBeginRequest();
    startTime = System.currentTimeMillis();
    }

    Reply


    PavanM Says:
    Posted at: April 20, 2009 at 3:39 pm

    Hello Jeroen,
    I was reading your article on JAMon and Jarep (http://java.dzone.com/articles/case-study-performance-tuning–0) I was quite impressed by the overall solution. Are you still using JAMon in your apps with Java5 ? Investigating on the right balance between JAMON and JMX on Java 5. Any comments ?
    Thanks,
    Pavan

    Reply


Leave a Reply

Click here to cancel reply.


Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • Xebia Sweden

Categories

  • Java (311)
  • Agile (181)
  • General (136)
  • Scrum (67)
  • Architecture (64)
  • Testing (59)
  • Performance (46)
  • Middleware (56)
    • Deployment (38)
  • Xebia Labs (39)
  • SOA (31)
  • Podcast (31)
  • Project Management (28)
  • Tools (26)
  • Uncategorized (20)
  • lean architecture (20)
  • Quality Assurance (17)
  • Articles (13)
  • Requirements Management (13)
  • Virtualization (19)

Tag Cloud

    SOA Eclipse lean architectuur Javascript Groovy Frameworks Java Spring Hibernate Scala Xebia Maven Flex Architecture Grails Oracle product owner Concurrency Control agile architectuur Agile Ajax Moving to India Scrum JPA Lean ACT TDD lean architecture XML JPA implementation patterns

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
Avatars by Sterling Adventures