AMX would me much more easier
https://glassfish.dev.java.net/javaee5/amx/docs/amx.html
Following sample would print monitoring info. of a jdbc connection pool at regular intervals.
Dependency : appserv-ext.jar
------------------------------------------------------------------------------------------------------------------------------
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import com.sun.appserv.management.client.AppserverConnectionSource;
import java.util.TimerTask;
import java.util.Timer;
public class JDBCConPoolMonitoringInfoCollector {
public static final String[] properties = {"numconnused-current", "numconndestroyed-count",
"numconncreated-count", "numconnacquired-count", "numconnreleased-count",
"averageconnwaittime-count", "connrequestwaittime-current", "numconnfailedvalidation-count",
"numconnnotsuccessfullymatched-count", "numconnsuccessfullymatched-count", "numconntimedout-count",
"waitqueuelength-count", "numpotentialconnleak-count"};
public static final String USER_PASSWORD = "adminadmin";
public static final int JMX_PORT = 8686;
public static final String DOTTED_NAME_GET = "dottedNameGet";
public static final String USER = "admin";
public static final String CONFIG = "server-config";
public static final String HOST_NAME = "localhost";
public static void main(String[] args)
throws Exception {
JDBCConPoolMonitoringInfoCollector client = new JDBCConPoolMonitoringInfoCollector();
client.runTest();
}
public void runTest() throws Exception {
Timer timer = new Timer();
timer.schedule(new Poller(), 1000, 1000 * 10);
}
class Poller extends TimerTask {
public void run() {
for (String property : properties) {
try {
int result = getMonitorablePropertyOfConnectionPool("<CONNECTION_POOL_NAME>",
property, HOST_NAME, JMX_PORT, USER, USER_PASSWORD, CONFIG);
System.out.println(property + " : " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("-------------------------------------------------------------------");
}
}
public int getMonitorablePropertyOfConnectionPool(String poolName, String property, String hostName, int JMX_PORT, String user, String password, String configName) throws Exception {
AppserverConnectionSource appserver =
new AppserverConnectionSource(AppserverConnectionSource.PROTOCOL_RMI, hostName, JMX_PORT, user, password, null);
MBeanServerConnection connection = appserver.getJMXConnector(false).getMBeanServerConnection();
ObjectName objectName =
new ObjectName("amx:j2eeType=X-MonitoringDottedNames,name=na");
String params[] = new String[]{String.class.getName()};
Object values[] = new Object[]{"server.resources." + poolName + "." + property};
javax.management.Attribute returnValue = (javax.management.Attribute) connection.invoke(objectName, DOTTED_NAME_GET, values, params);
return new Integer(returnValue.getValue().toString());
}
}
------------------------------------------------------------------------------------------------------------------------------
Thanks,
-Jagadish
[Message sent by forum member 'jr158900' (jr158900)]
http://forums.java.net/jive/thread.jspa?messageID=219858