• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMX sample code

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Wish everyone a a Very Happy New Year.

May the dawn of the new year bring prosperity to all.


I am looking for a JMX java sample code for monitoring JDBC connections that is compatible with websphere 6.1


Prompt help will be greatly appreciated.

I checked the PmiJmxTest.java on the IBM websphere knowledge base and it does not cover JDBC connection monitoring. I am enclosing the monitoring method here for reference.


/** Test V6 APIs */
public void doTestV6 ()
{
System.out.println ("\ndoTestV6() output:\n");

// the following methods are specific to V6 and demonstrates the V6 API..so set the flag to false
String v5PropFlag = System.setProperty ("websphereV5Statistics", "false");
try
{
Object[] params;
String[] signature;

// get current statistic set that is used for monitoring
System.out.println ("\nCurrent statistic set: " + ac.invoke(perfOName, "getStatisticSet", null, null));


// get all statistics from the server using Perf MBean
System.out.println ("\nGet all statistics in PMI tree");
signature = new String[]{"[Lcom.ibm.websphere.pmi.stat.StatDescriptor;","java.lang.Boolean"};
params = new Object[] {new StatDescriptor[]{new StatDescriptor(null)}, new Boolean(true)};

com.ibm.websphere.pmi.stat.WSStats[] wsStats = (com.ibm.websphere.pmi.stat.WSStats[])
ac.invoke(perfOName, "getStatsArray", params, signature);
System.out.println (wsStats[0].toString());


// get statistics from one JVM MBean using J2EE JMX
System.out.println ("\nGet JVM statistics using JVM MBean");
javax.management.j2ee.statistics.Stats j2eeStats = (javax.management.j2ee.statistics.Stats)
ac.getAttribute(jvmOName, "stats");
System.out.println (j2eeStats.toString());


// get statistics from a specific thread pool -- WebContainer thread pool
System.out.println ("\nGet statistics for a specific thread pool");
signature = new String[]{"[Lcom.ibm.websphere.pmi.stat.StatDescriptor;","java.lang.Boolean"};

StatDescriptor webContainerPoolSD = new StatDescriptor (new String[] {WSThreadPoolStats.NAME,
"WebContainer"});
params = new Object[] {new StatDescriptor[]{webContainerPoolSD}, new Boolean(true)};

wsStats = (com.ibm.websphere.pmi.stat.WSStats[])
ac.invoke(perfOName, "getStatsArray", params, signature);
System.out.println (wsStats[0].toString());


// set monitoring to statistic set "extended"
System.out.println ("\nSet monitoring to statistic set 'Extended'");
signature = new String[]{"java.lang.String"};
params = new Object[] {StatConstants.STATISTIC_SET_EXTENDED};

ac.invoke(perfOName, "setStatisticSet", params, signature);

// get current statistic set that is used for monitoring
System.out.println ("\nCurrent statistic set: "+ ac.invoke(perfOName, "getStatisticSet", null, null));


// selectively enable statistics for all thread pools
System.out.println ("\nSelectively enable statistics (ActiveCount and PoolSize statistics) for thread pool -- fine grained control");

StatDescriptor threadPoolSD = new StatDescriptor (new String[]
{WSThreadPoolStats.NAME});
// create a spec object to enable ActiveCount and PoolSize on the thread pool
StatLevelSpec[] spec = new StatLevelSpec[1];
spec[0] = new StatLevelSpec (threadPoolSD.getPath(), new int[]
{WSThreadPoolStats.ActiveCount, WSThreadPoolStats.PoolSize});

signature = new String[]{"[Lcom.ibm.websphere.pmi.stat.StatLevelSpec;","java.lang.Boolean"};
params = new Object[] {spec, new Boolean(true)};

ac.invoke(perfOName, "setInstrumentationLevel", params, signature);


// get current statistic set that is used for monitoring
System.out.println ("\nCurrent statistic set: "+ ac.invoke(perfOName, "getStatisticSet", null, null));

// get statistics from all thread pools
System.out.println ("\nGet statistics from all thread pools");
signature = new String[]{"[Lcom.ibm.websphere.pmi.stat.StatDescriptor;","java.lang.Boolean"};
params = new Object[] {new StatDescriptor[]{threadPoolSD},new Boolean(true)};

wsStats = (com.ibm.websphere.pmi.stat.WSStats[])
ac.invoke(perfOName, "getStatsArray", params, signature);
System.out.println (wsStats[0].toString());

}
catch (Exception e)
{
e.printStackTrace();
}

// set the property to original value
// System.setProperty ("websphereV5Statistics", v5PropFlag);
}


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic