import java.util.Properties; import java.util.Date; import java.util.Set; import java.util.HashSet; import java.util.Iterator; import javax.management.ObjectName; import com.ibm.websphere.management.AdminClient; import com.ibm.websphere.management.AdminClientFactory; import com.ibm.websphere.management.exception.ConnectorException; import com.ibm.websphere.pmi.*; import com.ibm.websphere.pmi.client.*; import com.ibm.websphere.pmi.stat.*; public class AdminClientExample { private AdminClient adminClient; private ObjectName queryName; private Set perfOns = new HashSet(); private static String username; private static String passwd; private static String host; private static String port; private static String serverName; public static void main(String[] args){ //username = args[0]; //passwd = args[1]; //host = args[2]; //port = args[3]; if(args.length > 0){ serverName = args[0]; } AdminClientExample ace = new AdminClientExample(); ace.createAdminClient(); if(serverName != null){ ace.getMBean(serverName); } else{ ace.getMBean(); } ace.getStats(); } private void createAdminClient(){ String wasPath = "/usr/websphere/AppServer/profiles/FS_DM_01"; String trustStore = "DummyClientTrustFile.jks"; String keyStore = "DummyClientKeyFile.jks"; String trustStorePw = "WebAS"; String keyStorePw = "WebAS"; Properties connectProps = new Properties(); connectProps.setProperty(AdminClient.CONNECTOR_TYPE,AdminClient.CONNECTOR_TYPE_SOAP); connectProps.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED,"true"); connectProps.setProperty(AdminClient.CONNECTOR_AUTO_ACCEPT_SIGNER,"true"); connectProps.setProperty(AdminClient.CACHE_DISABLED,"false"); connectProps.setProperty("javax.net.ssl.trustStore", wasPath + "/etc/DummyClientTrustFile.jks"); connectProps.setProperty("javax.net.ssl.keyStore", wasPath+"/etc/DummyClientKeyFile.jks"); connectProps.setProperty("javax.net.ssl.trustStorePassword",trustStorePw); connectProps.setProperty("javax.net.ssl.keyStorePassword",keyStorePw); connectProps.setProperty(AdminClient.CONNECTOR_HOST,"localhost"); connectProps.setProperty(AdminClient.CONNECTOR_PORT,"8879"); connectProps.setProperty(AdminClient.USERNAME,"wasadmin"); connectProps.setProperty(AdminClient.PASSWORD,"Ngboss#0902"); System.setProperty("was.install.root","/usr/websphere/AppServer"); try{ adminClient = AdminClientFactory.createAdminClient(connectProps); } catch(Exception e){ e.printStackTrace(); } } private void getMBean(){ String query = "WebSphere:type=Perf,*"; Set mBeans = null; try{ mBeans = adminClient.queryNames(new ObjectName(query),null); }catch(Exception e){ e.printStackTrace(); } Iterator mi = mBeans.iterator(); while(mi.hasNext()){ try{ ObjectName on = (ObjectName)mi.next(); String proc = on.getKeyProperty("process"); if(proc !=null && proc.equals("nodeagent")){ continue; } else{ perfOns.add(on); } } catch(Exception e){ e.printStackTrace(); } } } private void getMBean(String objectName){ String query = "WebSphere:process=" + objectName +",type=Perf,*"; Set mBeans = null; try{ mBeans = adminClient.queryNames(new ObjectName(query),null); }catch(Exception e){ e.printStackTrace(); } Iterator mi = mBeans.iterator(); while(mi.hasNext()){ try{ ObjectName on = (ObjectName)mi.next(); String proc = on.getKeyProperty("process"); if(proc !=null && proc.equals("nodeagent")){ continue; } else{ perfOns.add(on); } } catch(Exception e){ e.printStackTrace(); } } } private void getStats(){ Iterator pi = perfOns.iterator(); while(pi.hasNext()){ try{ ObjectName perfOn = (ObjectName)pi.next(); String serverName = perfOn.getKeyProperty("process"); String wsStatsName; Object[] params; String[] signature; com.ibm.websphere.pmi.stat.WSStats[] wsStats; signature = new String[]{"[Lcom.ibm.websphere.pmi.stat.StatDescriptor;","java.lang.Boolean"}; StatDescriptor webContainerPoolSD = new StatDescriptor(new String[] {WSThreadPoolStats.NAME, "WebContainer"}); StatDescriptor jvmSD = new StatDescriptor(new String[] {WSJVMStats.NAME}); StatDescriptor jdbcSD = new StatDescriptor(new String[] {WSJDBCConnectionPoolStats.NAME,"Oracle JDBC Driver (XA)"}); StatDescriptor servletSD = new StatDescriptor(new String[] {WSWebAppStats.NAME,"CRM_CRM_FS.war#CRM_CRM.war"}); StatDescriptor jtaSD = new StatDescriptor(new String[] {WSJTAStats.NAME}); params = new Object[] {new StatDescriptor[]{webContainerPoolSD,jvmSD,jdbcSD,servletSD,jtaSD}, new Boolean(true)}; wsStats = (com.ibm.websphere.pmi.stat.WSStats[])adminClient.invoke(perfOn, "getStatsArray", params, signature); System.out.println(serverName); for(int i=0;i