Version 3.10.0

hirondelle.web4j.webmaster
Class PerformanceMonitor

Object
  extended by hirondelle.web4j.webmaster.PerformanceMonitor
All Implemented Interfaces:
Filter

public final class PerformanceMonitor
extends Object
implements Filter

Compile simple performance statistics, and use periodic pings to detect trouble.

See web.xml for more information on how to configure this Filter.

Performance Statistics

This class stores a Collection of PerformanceSnapshot objects in memory (not in a database).

The presentation of these performance statistics in a JSP is always "one behind" this class. This Filter examines the response time of each fully processed request. Any JSP presenting the response times, however, is not fully processed from the point of view of this filter, and has not yet contributed to the statistics.

It is important to note that Filter objects must be designed to operate safely in a multi-threaded environment. Using the nomenclature of Effective Java, this class is 'conditionally thread safe' : the responsibility for correct operation in a multi-threaded environment is shared between this class and its caller. See getPerformanceHistory() for more information.

Periodic Pings (Full Version Only)

You can optionally have this filter do periodic pings on an application URL, by adding an init-param to the filter config of the form:
<init-param>  
  <param-name>BadResponseDetector</param-name>
  <param-value>http://www.blah.com/whatever.do, 5, 30</param-value>
</init-param>

The BadRequestDetector setting specifies 3 items separated by a comma:
  1. a single target URL. This target URL should not require user login, and should represent an action which accesses the database.
  2. a ping frequency (in minutes, range 1..60).
  3. a timeout value (in seconds, range 1..60).

Pings begin shortly after this filter is first initialized. Each ping does a GET for the target URL in a background thread. These ping operations look for two kinds of problems :

If a problem is detected, a short TroubleTicket describing the problem is sent to the TroubleTicketMailingList recipients configured in web.xml.

Applications may not respond normally to HTTP requests for various reasons :

This class runs as part of your application. Of course, it's unable to detect when your app itself is not running. However, it's still quite useful, and will catch many important errors. If desired, you can use sites such as SiteUptime.com to monitor your site using external tools.


Constructor Summary
PerformanceMonitor()
           
 
Method Summary
 void destroy()
          This implementation does nothing.
 void doFilter(ServletRequest aRequest, ServletResponse aResponse, FilterChain aChain)
          Calculate server response time, and store relevant statistics in memory.
static List<PerformanceSnapshot> getPerformanceHistory()
          Return statistics on recent application performance.
 void init(FilterConfig aFilterConfig)
          Read in the configuration of this filter from web.xml.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PerformanceMonitor

public PerformanceMonitor()
Method Detail

init

public void init(FilterConfig aFilterConfig)
Read in the configuration of this filter from web.xml.

The config is validated, gathering of statistics is begun, and any periodic ping operations are initialized.

Specified by:
init in interface Filter

destroy

public void destroy()
This implementation does nothing.

Specified by:
destroy in interface Filter

doFilter

public void doFilter(ServletRequest aRequest,
                     ServletResponse aResponse,
                     FilterChain aChain)
              throws IOException,
                     ServletException
Calculate server response time, and store relevant statistics in memory.

Specified by:
doFilter in interface Filter
Throws:
IOException
ServletException

getPerformanceHistory

public static List<PerformanceSnapshot> getPerformanceHistory()
Return statistics on recent application performance.

A static method is the only way an Action can access this data, since it has no access to the Filter object itself (which is built by the container).

The typical task for the caller is iteration over the return value. The caller must synchronize this iteration, by obtaining the lock on the return value. The typical use case of this method is :

 List history = PerformanceMonitor.getPerformanceHistory();
 synchronized(history) {
   for(PerformanceSnapshot snapshot : history){
     //..elided
   }
 }
 


Version 3.10.0

Copyright Hirondelle Systems. Published September 20, 2008 - User Guide - All Docs.