Oracle GlassFish Server 3.0.1 Monitoring Scripting Client Installation and Quick Start Guide

ProcedureTo Generate a Timer Statistic

Timer statistics typically correspond to multiple events. For example, to calculate the time to process a request, two events are required, for example, a “request received” event and a “request completed” event.

For operations that have a measurable duration, Monitoring Scripting Client provides pairs of events to indicate the start and the end of the operations. For example, to indicate the initiation and completion of an HTTP request that has been received by the web container, Monitoring Scripting Client provides the following pair of events:

Use pairs of events that indicate the start and end of an operation to generate a timer statistic.

  1. Write an event callback function to calculate the start time.

  2. Ensure that the function to calculate the start time is called when the “operation started” event is received.

    For details, see To Register a Script as a Listener for an Event.

  3. Write an event callback function to calculate the end time.

  4. Ensure that the function to calculate the end time is called when the “operation ended” event is received.

    For details, see To Register a Script as a Listener for an Event.


Example 1–7 Generating a Timer Statistic

This example uses the following events to measure the time to process web service requests:

The events for a single request are sent in the same thread of control. Therefore, the identity of the thread can be used as a key to associate the start event and the end event for the request.

For the complete listing of the script from which this example is extracted, see Example 1–9.

...
var startTime;
var object = new Object();
...

function requestStartEvent(appName,hostName,serverName,serverPort,contextPath,
    servletPath){

	...
        startTime = (new Date()).getTime();
	//insert the request time in Map
        key = java.lang.Thread.currentThread().getId();
        object[key] = startTime;
        ...
}
scriptContainer.registerListener('glassfish:web:http-service:requestStartEvent',
    request_params , 'requestStartEvent');
...
function requestEndEvent(appName,hostName,serverName,serverPort,contextPath,
    servletPath,statusCode){

...
        key = java.lang.Thread.currentThread().getId();
        startTime = object[key];
        if (startTime == null)
            client.print("Error getting the startTime for thread = " + key);
        else
            delete[key];
        totalTime = (new Date()).getTime() - startTime;
        ...
}
scriptContainer.registerListener('glassfish:web:http-service:requestEndEvent', 
    request1_params, 'requestEndEvent');