/*********************************** * Configurable vars ***********************************/ String url = "t3://localhost:8001" ; String userName = "system" ; String password = "password" ; String serverName = "clusterAdminServer" ; int SLEEP_VALUE=30000; boolean LOG_TO_FILE=false; String OUTPUT_FILE_NAME="JDBCConnectionPool.out"; /********* End Config Vars *********************/ import java.util.Iterator; import java.util.Set; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import weblogic.jndi.Environment; import weblogic.jndi.WLInitialContextFactory; import weblogic.management.runtime.JDBCConnectionPoolRuntimeMBean; import weblogic.management.configuration.ServerMBean; import weblogic.management.MBeanHome; Set jdbcRuntimeList = null; /** * method */ getJDBCRuntime() { print("Getting JDBCRuntimes..."); // Get InitialContext print("Get InitialContext..."); Environment env = new Environment(); env.setProviderUrl(url); env.setSecurityPrincipal(userName); env.setSecurityCredentials(password); Context ctx = env.getInitialContext(); print("Got IntitialContext."); mBeanHome = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME); jdbcRuntimeList = mBeanHome.getMBeansByType("JDBCConnectionPoolRuntime"); return jdbcRuntimeList; } sleep(int sleepValue) { print("Sleeping for " + sleepValue + " milliseconds."); Thread.currentThread().sleep(sleepValue); } appendToFile(String aString) { FileOutputStream fos = new FileOutputStream(OUTPUT_FILE_NAME, true); fos.write(aString.getBytes()); char cr = '\n'; fos.write(cr); fos.close(); } /** * MAIN */ try { while(true) { //jdbcRuntimeList = getJDBCRuntime(); getJDBCRuntime(); if (jdbcRuntimeList != null) { Iterator iter = jdbcRuntimeList.iterator(); while(iter.hasNext()) { JDBCConnectionPoolRuntimeMBean aJDBCRuntime = (JDBCConnectionPoolRuntimeMBean)iter.next(); // active connections current count int activeConnCurrentCount = aJDBCRuntime.getActiveConnectionsCurrentCount(); // waiting for connection current count int waitingForConnCurrentCount = aJDBCRuntime.getWaitingForConnectionCurrentCount(); // waiting for connection high count int waitingForConnHighCount = aJDBCRuntime.getWaitingForConnectionHighCount(); // wait seconds high count int waitSecondsHighCount = aJDBCRuntime.getWaitSecondsHighCount(); StringBuffer buf = new StringBuffer("Active conn current count: "); buf.append(activeConnCurrentCount); buf.append(" "); buf.append("Waiting for conn current count: "); buf.append(waitingForConnCurrentCount); buf.append(" "); buf.append("Waiting for conn high count: "); buf.append(waitingForConnHighCount); buf.append(" "); buf.append("Wait seconds high count: "); buf.append(waitSecondsHighCount); buf.append(" "); buf.append(aJDBCRuntime.toString()); print(buf.toString()); if (LOG_TO_FILE) appendToFile(buf.toString()); } } sleep(SLEEP_VALUE); } } catch(Exception e) { print("Exception caught: " + e); System.exit(-1); }