Monitor Requests Snippet

This snippet displays informations about the requests that come into your XWiki system, the time each request took, the unfinished requests, the list of the latest requests, etc. This code was originally created by Raffaello Pelagalli.

This code snippet is not included at XWiki.RequestsStatus since XE 1.4M2 and above

1 XWiki Monitoring

#set($monitor = $xwiki.getXWiki().getPluginManager().getPlugin("monitor"))
#if($monitor && $monitor.isActive())

  #set($threadname = $request.thread)
  #if($threadname)
    #set($activeTimers = $monitor.getActiveTimerData())
    #foreach($thread in $activeTimers.keySet())
      #set($req = $activeTimers.get($thread))
      #if($req.threadName.equals($threadname))
        * URL: $req.getURL() Page: $req.getWikiPage()
        * StartDate: $req.startTime
        * State: $thread.getState() Alive: $thread.isAlive() [${threadname}>${doc.fullName}?thread=${threadname}&kill=1]
        #if($request.kill)
          Interrupting $thread.stop()
        #end
      #end
    #end
  #else
  
    1.1 Consolidated Data

    #set($dur = $xwiki.parseInt("${monitor.duration}"))
    #set($nbreq = $xwiki.parseInt("${monitor.requests}"))
    #set($avg = ($dur/$nbreq))

    * Duration: ${monitor.getDuration()} ms
    * Requests: $monitor.getRequests()
    * Average: ${avg} ms

    #foreach($timer in $monitor.getTimerSummaries())
      #set($dur = $xwiki.parseInt("${timer.duration}"))
      #set($nbreq = $xwiki.parseInt("${timer.requests}"))
      #set($avg = ($dur/$nbreq))
      * $timer.name duration: ${timer.duration} ms Calls: $timer.nbCalls Requests: $timer.requests Average: ${avg} ms
    #end

    1.1 Active requests

    Currently running requests. There is always at least the request for this page.

    #set($timerdata = $monitor.getActiveTimerData())
    Active requests size: $timerdata.size()

    #foreach($req in $timerdata)
      * Page: $req.getWikiPage()
      * URL: $req.getURL()
      * Thread: [$req.threadName>${doc.fullName}?thread=${req.threadName}]
      * StartDate: $req.startTime
    #end

    1.1 Latest unfinished requests

    These are requests that didn't reach "endRequest", but where cleaned-up by a reuse of threads. Only 32 requests max are kept in memory.

    #set($timerdata = $monitor.getLastUnfinishedTimerData())
    Active requests size: $timerdata.size()

    #foreach($req in $timerdata)
      * Page: $req.getWikiPage()
      * URL: $req.getURL()
      * Thread: [$req.threadName>${doc.fullName}?thread=${req.threadName}]
      * StartDate: $req.startTime
    #end

    1.1 Latest requests

    Latest requests that finished properly. Only $timerdata.maxSize() requests max are kept in memory.

    #set($timerdata = $monitor.getLastTimerData())
    Numbers of requests displayed: $timerdata.size() 
    #foreach($req in $timerdata)
      * URL: $req.getURL()
      * Page: $req.getWikiPage()
      * Thread: $req.threadName
      * Duration: $req.duration
      * StartDate: $req.startTime
      * EndDate: $req.endTime
      #foreach($timer in $req.timerList)
        ** $timer
      #end
      \\
    #end
  #end
#else
  #warning("The Monitor plugin is disabled. Please enable it by setting <tt>xwiki.monitor=1</tt> in your <tt>xwiki.cfg</tt> configuration file.")
#end
Version 1.2 last modified by VincentMassol on 24/04/2008 at 09:35

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: VincentMassol on 2008/04/24 09:32
This wiki is licensed under a Creative Commons license
1.4.1.10194