JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle GlassFish Server 3.1 Administration Guide
search filter icon
search icon

Document Information

Preface

1.  Overview of GlassFish Server Administration

Default Settings and Locations

Configuration Tasks

Administration Tools

Instructions for Administering GlassFish Server

Part I Runtime Administration

2.  General Administration

3.  Administering Domains

4.  Administering the Virtual Machine for the Java Platform

5.  Administering Thread Pools

6.  Administering Web Applications

7.  Administering the Logging Service

8.  Administering the Monitoring Service

9.  Writing and Running JavaScript Clients to Monitor GlassFish Server

Running a Script for Monitoring GlassFish Server

To Run a Script for Monitoring GlassFish Server

Writing Scripts in the JavaScript Language for Monitoring GlassFish Server

Obtaining Information About Events That Provide Monitoring Data

To Obtain a List of Events That Provide Monitoring Data

To Obtain Detailed Information About an Event That Provides Monitoring Data

To Register a Script as a Listener for an Event

To Display Information From a Script

Writing an Event Callback Function

To Generate Counter Statistics

To Generate a Timer Statistic

Sample JavaScript Programs for Monitoring GlassFish Server

JavaScript Monitoring Client API Reference

Object client

Method Summary

Method Detail

Object scriptContainer

Method Summary

Method Detail

10.  Administering Life Cycle Modules

11.  Extending and Updating GlassFish Server

Part II Resources and Services Administration

12.  Administering Database Connectivity

13.  Administering EIS Connectivity

14.  Administering Internet Connectivity

15.  Administering the Object Request Broker (ORB)

16.  Administering the JavaMail Service

17.  Administering the Java Message Service (JMS)

18.  Administering the Java Naming and Directory Interface (JNDI) Service

19.  Administering Transactions

Part III Appendixes

A.  Subcommands for the asadmin Utility

Index

Sample JavaScript Programs for Monitoring GlassFish Server

The sample JavaScript programs in this section show how to use GlassFish Server events to generate and present statistics for system administrators who are monitoring GlassFish Server.

Example 9-8 Counting the Number of Loaded JSP Technology Pages

This example uses the glassfish:web:jsp:jspLoadedEvent event to count the number of JavaServer Pages (JSP) technology pages that GlassFish Server has loaded.

var njspLoaded=0;

function jspLoaded(hostName) {
    njspLoaded = njspLoaded + 1;
    client.print( '\n js> jsp loaded event called on ' +
            'host = ' + hostName +
            ' and count = ' + njspLoaded);
}

params = java.lang.reflect.Array.newInstance(java.lang.String, 1);
params[0]="hostName";

scriptContainer.registerListener('glassfish:web:jsp:jspLoadedEvent', 
    params, 'jspLoaded');

This script can be run with a command similar to the following:

asadmin run-script jsp-loaded-count.js

Information similar to the following is displayed each time that GlassFish Server loads a JSP technology page:

 js> jsp loaded event called on host = server and count = 1

The script runs until a user types Ctrl-C to stop the script.

Example 9-9 Measuring the Time to Process Web Service Requests

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

The script also displays the information that is contained in the parameters of these events.

// http request related probes

// glassfish:web:http-service:requestStartEvent requestStartEvent(
// java.lang.String appName,
// java.lang.String hostName,
// java.lang.String serverName,
// int serverPort,
// java.lang.String contextPath,
// java.lang.String servletPath)


request_params = java.lang.reflect.Array.newInstance(java.lang.String, 6);
request_params[0]="appName";
request_params[1]="hostName";
request_params[2]="serverName";
request_params[3]="serverPort";
request_params[4]="contextPath";
request_params[5]="servletPath";

var startTime;
var object = new Object();
var nrequestStartEvent=0;

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

    nrequestStartEvent=nrequestStartEvent+1;
        startTime = (new Date()).getTime();
    //insert the request time in Map
        key = java.lang.Thread.currentThread().getId();
        object[key] = startTime;

        client.print(
            'Count: '+ nrequestStartEvent +'\n'+ 
            'Event: glassfish:web:http-service:requestStartEvent' +'\n'+ 
            'Application: '+appName+'\n'+ 
            'Host: ' + hostName +'\n'+ 
            'Server: ' + serverName +'\n'+ 
            'HTTP Port: ' + serverPort +'\n'+ 
            'Context Path: ' + contextPath +'\n'+ 
            'Servlet Path: ' + servletPath + '\n' + 
            'Current Thread: ' + java.lang.Thread.currentThread().getId() + 
        '\n\n');
}

scriptContainer.registerListener('glassfish:web:http-service:requestStartEvent',
    request_params , 'requestStartEvent');

// glassfish:web:http-service:requestEndEvent requestEndEvent(
// java.lang.String appName,
// java.lang.String hostName,
// java.lang.String serverName,
// int server Port,
// java.lang.String contextPath,
// java.lang.String servletPath,
// int statusCode)

request1_params = java.lang.reflect.Array.newInstance(java.lang.String, 7);
request1_params[0]="appName";
request1_params[1]="hostName";
request1_params[2]="serverName";
request1_params[3]="serverPort";
request1_params[4]="contextPath";
request1_params[5]="servletPath";
request1_params[6]="statusCode";


var nrequestEndEvent=0;

function requestEndEvent(appName,hostName,serverName,serverPort,contextPath,
    servletPath,statusCode){

    nrequestEndEvent=nrequestEndEvent+1;
        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;

        client.print(
            'Time Taken: ' + ((new Date()).getTime()-startTime) + ' ms\n' + 
            'Count: '+nrequestEndEvent+'\n'+ 
            'Event: glassfish:web:http-service:requestEndEvent' +'\n'+ 
            'Application: '+appName+'\n'+ 
            'Host: ' + hostName +'\n'+ 
            'Server: ' + serverName +'\n'+ 
            'HTTP Port: ' + serverPort +'\n'+ 
            'Context Path: ' + contextPath +'\n'+ 
            'Servlet Path: ' + servletPath +'\n'+ 
            'Status Code: ' + statusCode + '\n' + 
            'Current Thread: ' + java.lang.Thread.currentThread().getId() + '\n' + 
         '\n\n');
}
scriptContainer.registerListener('glassfish:web:http-service:requestEndEvent', 
    request1_params, 'requestEndEvent');

This script can be run with a command similar to the following:

asadmin run-script web-service-request-timer.js

Information similar to the following is displayed each time that a web service request is initiated:

Count: 2
Event: glassfish:web:http-service:requestStartEvent
Application: __admingui
Host: __asadmin
Server: localhost
HTTP Port: 4848
Context Path: 
Servlet Path: /common/commonTask.jsf
Current Thread: 98

Information similar to the following is displayed each time that a web service request is completed:

Time Taken: 1704 ms
Count: 2
Event: glassfish:web:http-service:requestEndEvent
Application: __admingui
Host: __asadmin
Server: localhost
HTTP Port: 4848
Context Path: 
Servlet Path: /common/commonTask.jsf
Status Code: 200
Current Thread: 98

The script runs until a user types Ctrl-C to stop the script.