BEA Home | Events | Solutions | Partners | Products | Services | Download | Developer Center | WebSUPPORT
| WebLogic Server Doc Home | Programming JMX | Previous Topic | Next Topic | Contents | View as PDF

Monitoring WebLogic Server MBeans

The following sections provide an overview of how to monitor WebLogic Server MBean attributes:

- Overview

- Setting Up Monitoring

- Sample Monitoring Scenarios

Overview

A WebLogic Server client can set up monitors to monitor one or more MBean attributes. The various types of monitors are defined in the JMX documentation for the package javax.management.monitor. Standard JMX monitors are:

- CounterMonitor, for observing integer attributes

- GaugeMonitor, for observing integer or floating point attributes

- StringMonitor, for observing string attributes

JMX monitors frequently act as notification broadcasters, to indicate when a certain condition has been met in a monitor. For this reason, monitoring systems generally include standard notification constructs, such as notification listeners and notification filters, which are registered with the monitor.

Setting Up Monitoring

The following is an example of how to set up a counter monitor for receiving JMX Notifications. Because this example also uses a notification listener to observe the monitor's notifications, some of the information builds from the examples in Using MBean Notifications.

Creating a Notification Listener

The example begins by building a notification listener, named CounterListener, that will receive notifications emitted from a JMX monitor:

>     import java.rmi.Remote;

>     import javax.management.Notification;

>     import javax.management.monitor.MonitorNotification;

>     import weblogic.management.RemoteNotificationListener;

>     public class CounterListener implements RemoteNotificationListener {

>         String message;

>         public void handleNotification(Notification notification ,Object obj) {

>             System.out.println("\njavax.management.Notification");

>             System.out.println("            type = " +

>                                notification.getType());

>             System.out.println("  sequenceNumber = " +

>                                notification.getSequenceNumber());

>             System.out.println("          source = " +

>                                notification.getSource());

>             System.out.println("       timestamp = " +

>                                notification.getTimeStamp() + "\n");

>             if(notification instanceof MonitorNotification) {

>                 MonitorNotification monitorNotification =

>                                     (MonitorNotification) notification;

>                 System.out.println("\njavax.management.monitor.MonitorNotification");

>                 System.out.println("  observed attr = " +

>                                    monitorNotification.getObservedAttribute() );

>                 System.out.println("   observed obj =" +

>                                    monitorNotification.getObservedObject() );

>                 System.out.println("  trigger value =" +

>                                    monitorNotification.getTrigger() + "\n");

>                 message = "Mbean: " + monitorNotification.getObservedAttribute() +

>                           "\n" +

>                           "Attribute: " + monitorNotification.getObservedObject() +

>                           "\n" +

>                           "Trigger Value: " + monitorNotification.getTrigger();

>             }

>         }

>     }

Instantiating the Listener and Monitor

The example monitor class instantiates both the listener and monitor object, and registers the monitor to observe the ServerSecurityRuntime.InvalidLoginAttemptsTotalCount attribute. This attribute indicates the number of failed logins to the server

When the invalid login attempts exceed a threshold value, the handleNotification method is invoked by the notification listener, CounterListener.handleNotification().

The sample monitor code is as follows:

>     import java.rmi.RemoteException;

>     import java.util.Set;

>     import java.util.Iterator;

>     import javax.management.*;

>     import javax.management.AttributeChangeNotification;

>     import javax.management.AttributeChangeNotificationFilter;

>     import javax.management.monitor.CounterMonitor;

>     import javax.naming.*;

>     import weblogic.jndi.Environment;

>     import weblogic.management.*;

>     import weblogic.management.configuration.ServerMBean;

>     import weblogic.management.monitor.*;

>     import weblogic.management.runtime.ServerRuntimeMBean;

>     public class InvalidLoginMonitor {

>         public static void main (String args[]) {

>             // make sure there is a password argument

>             if (args.length != 3) {

>                 System.out.println("Usage: java InvalidLoginMonitor " +

>                                    "<system password> " +

>                                    "<domain name> " +

>                                    "<server name>");

>                 return;

>             }

>             String url      = "t3://localhost:7001";

>             String username = "system";

>             String password = args[0];

>             MBeanHome home  = null;

>             try {

>                 Environment env = new Environment();

>                 env.setProviderUrl(url);

>                 env.setSecurityPrincipal(username);

>                 env.setSecurityCredentials(password);

>                 Context ctx = env.getInitialContext();

>                 home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);

>                 System.out.println("Got the MBeanHome " + home);

>                 RemoteMBeanServer rmbs = home.getMBeanServer();

>                 CounterMonitor monitor = new CounterMonitor();

>                 CounterListener listener = new CounterListener();

>                 WebLogicObjectName monitorObjectName =

>                        new WebLogicObjectName("MyCounter",

>                                               "CounterMonitor",

>                                               args[1],

>                                               args[2]);

>                 WebLogicObjectName securityRtObjectName =

>                        new WebLogicObjectName("myserver",

>                                               "ServerSecurityRuntime",

>                                               args[1],

>                                               args[2]);

>                 Long t = new Long(2);

>                 Long offset = new Long(0);

>                 monitor.setThreshold((Number)t);

>                 monitor.setNotify(true);

>                 monitor.setOffset((Number)offset);

>                 monitor.setObservedAttribute("InvalidLoginAttemptsTotalCount");

>                 monitor.setObservedObject(securityRtObjectName);

>                 monitor.addNotificationListener(listener, null, null);

>                 monitor.preRegister(rmbs, monitorObjectName);

>                 monitor.start();

>             } catch (Exception e) {

>                 e.printStackTrace();

>             }

>         }

>     }

Note: The above example uses the hard-coded server name, "myserver," when creating the WebLogicObjectName. You must pass "myserver" as an argument when running this example or modify the code to use a different server name.

Sample Monitoring Scenarios

This section outlines some typical MBean attributes that you might consider monitoring to observe performance and/or resource usage. For more details on individual MBean attributes or methods, see the appropriate MBean API documentation.

JDBC Monitoring

The JDBCConnectionPoolRuntime MBean maintains several attributes that describe the connections to a deployed JDBC connection pool. Applications may monitor these attributes to observe the connection delays and connection failures, as well as connection leaks. The following table outlines those MBean attributes typically used for JDBC monitoring.

JDBCConnectionPoolRuntime MBean Attribute | Typical Monitoring Application
--- | ---
LeakedConnectionCount | Notify a listener when the total number of leaked connections reaches a predefined threshold. Leaked connections are connections that have been checked out but never returned to the connection pool via a close() call; it is important to monitor the total number of leaked connections, as a leaked connection cannot be used to fulfill later connection requests.
ActiveConnectionsCurrentCount | Notify a listener when the current number of active connections to a specified JDBC connection pool reaches a predefined threshold.
ConnectionDelayTime | Notify a listener when the average time to connect to a connection pool exceeds a predefined threshold.
FailuresToReconnect | Notify a listener when the connection pool fails to reconnect to its datastore. Applications may notify a listener when this attribute increments, or when the attribute reaches a threshold, depending on the level of acceptable downtime.

Copyright © 2001 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.