From: <gla...@hy...> - 2010-05-10 21:55:41
|
Author: glaullon Date: 2010-05-10 14:55:32 -0700 (Mon, 10 May 2010) New Revision: 14583 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14583 Added: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/StatsDefaultCollector.java Removed: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminMeasurementPlugin.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminServerCollector.java Modified: trunk/plugins/websphere/etc/hq-plugin.xml trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ApplicationCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ConnectionPoolCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/EJBCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ThreadPoolCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebappCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereCollector.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereProductPlugin.java trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereServerCollector.java Log: [HHQ-3971] After Websphere is restarted, all metrics stop collecting. Modified: trunk/plugins/websphere/etc/hq-plugin.xml =================================================================== --- trunk/plugins/websphere/etc/hq-plugin.xml 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/etc/hq-plugin.xml 2010-05-10 21:55:32 UTC (rev 14583) @@ -109,11 +109,6 @@ </metrics> <metrics name="WebSphere Admin 6.0" include="jvm"> - <metric name="Availability" - template="${domain}:Module=adminModule:${alias}" - category="AVAILABILITY" - indicator="true"/> - <metric name="Number of JVMs" alias="NumJVMs" template="${domain}:Module=adminModule:${alias}" @@ -483,11 +478,10 @@ value="properties/version/WAS.product"/> <plugin type="measurement" - class="WebsphereAdminMeasurementPlugin"/> + class="WebsphereJmxMeasurementPlugin"/> <plugin type="collector" class="WebsphereServerCollector"/> - <!--class="WebsphereAdminServerCollector"/--> <plugin type="control" class="WebsphereControlPlugin"/> Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ApplicationCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ApplicationCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ApplicationCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -27,53 +27,27 @@ import org.hyperic.hq.product.PluginException; +import javax.management.ObjectName; + import com.ibm.websphere.management.AdminClient; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class ApplicationCollector extends WebsphereCollector { - private static final Log log = LogFactory.getLog(ApplicationCollector.class.getName()); - protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); + ObjectName name = newObjectNamePattern("j2eeType=J2EEApplication," + + "name=" + getModuleName() + "," + + getProcessAttributes()); - this.name = - newObjectNamePattern("j2eeType=J2EEApplication," + - "name=" + getModuleName() + "," + - getProcessAttributes()); - - try { - this.name = resolve(mServer, this.name); - } catch (PluginException e) { - //XXX 6.0 hack - if (getModuleName().equals("adminconsole")) { - this.name = null; - } - else { - throw e; - } - } + setObjectName(resolve(mServer, name)); } - public void collect() { - if (this.name == null) { - setAvailability(true); - return; - } - try{ - Object state = - getAttribute(getMBeanServer(), this.name, "state"); - - if ((state == null) || (!(state instanceof Integer))) { - setAvailability(false); - } - else { - setAvailability(((Integer)state).intValue()==1); - } - }catch(PluginException e){ + public void collect(AdminClient mServer) throws PluginException { + Object state = getAttribute(mServer, getObjectName(), "state"); + if ((state == null) || (!(state instanceof Integer))) { setAvailability(false); - setMessage(e.getMessage()); + } else { + setAvailability(((Integer) state).intValue() == 1); } } } Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ConnectionPoolCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ConnectionPoolCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ConnectionPoolCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -35,9 +35,14 @@ import org.hyperic.hq.product.PluginException; import com.ibm.websphere.management.AdminClient; +import java.util.Arrays; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; public class ConnectionPoolCollector extends WebsphereCollector { + private static final Log log = LogFactory.getLog(ConnectionPoolCollector.class.getName()); + private static final String[][] ATTRS = { //basic (default) PMI level { "CreateCount", "numCreates" }, @@ -92,35 +97,25 @@ } protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); + ObjectName name = newObjectNamePattern("type=JDBCProvider," + + "j2eeType=JDBCResource," + + "name=" + getModuleName() + "," + + getProcessAttributes()); + setObjectName(resolve(mServer, name)); + } - this.name = - newObjectNamePattern("type=JDBCProvider," + - "j2eeType=JDBCResource," + - "name=" + getModuleName() + "," + - getProcessAttributes()); + public void collect(AdminClient mServer) throws PluginException { + JDBCStats stats = (JDBCStats) getStats(mServer, getObjectName()); - this.name = resolve(mServer, this.name); - } + if (stats == null) { + throw new PluginException("Stats not found"); + } - public void collect() { - AdminClient mServer = getMBeanServer(); - if (mServer == null) { - return; + Stats[] pools = stats.getConnectionPools(); + if (pools.length != 1) { + throw new PluginException("Pool not found (" + pools.length + ")"); } - try { - JDBCStats stats = (JDBCStats)getStats(mServer, this.name); - if (stats == null) { - return; - } - setAvailability(true); - Stats[] pools = stats.getConnectionPools(); - for (int i=0; i<pools.length; i++) { - collectStatCount(pools[i], ATTRS); - } - } catch (PluginException e) { - setAvailability(false); - setMessage(e.getMessage()); - } + collectStatCount(pools[0], ATTRS); + setAvailability(true); } } Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/EJBCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/EJBCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/EJBCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -29,11 +29,11 @@ import com.ibm.websphere.management.AdminClient; +import javax.management.ObjectName; + public class EJBCollector extends WebsphereCollector { protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); - String module = getModuleName(); int ix = module.indexOf('#'); if (ix == -1) { @@ -42,29 +42,20 @@ String app = module.substring(0, ix); String ejb = module.substring(ix+1); - this.name = - newObjectNamePattern("j2eeType=EJBModule," + - "J2EEApplication=" + app + "," + - "name=" + ejb + "," + - getProcessAttributes()); + ObjectName name = newObjectNamePattern("j2eeType=EJBModule," + + "J2EEApplication=" + app + "," + + "name=" + ejb + "," + + getProcessAttributes()); - this.name = resolve(mServer, this.name); + setObjectName(resolve(mServer, name)); } - public void collect() { - try { - Object ejbs = - getAttribute(getMBeanServer(), this.name, "ejbs"); - - if (ejbs == null) { - setAvailability(false); - } - else { - setAvailability(true); - } - } catch (PluginException e) { + public void collect(AdminClient mServer) throws PluginException { + Object ejbs = getAttribute(mServer, getObjectName(), "ejbs"); + if (ejbs == null) { setAvailability(false); - setMessage(e.getMessage()); + } else { + setAvailability(true); } } } Added: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/StatsDefaultCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/StatsDefaultCollector.java (rev 0) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/StatsDefaultCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -0,0 +1,52 @@ +/* + * NOTE: This copyright does *not* cover user programs that use HQ + * program services by normal system calls through the application + * program interfaces provided as part of the Hyperic Plug-in Development + * Kit or the Hyperic Client Development Kit - this is merely considered + * normal use of the program, and does *not* fall under the heading of + * "derived work". + * + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of HQ. + * + * HQ is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ +package org.hyperic.hq.plugin.websphere; + +import javax.management.j2ee.statistics.Stats; + +import org.hyperic.hq.product.PluginException; + +import com.ibm.websphere.management.AdminClient; +import java.util.Arrays; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public abstract class StatsDefaultCollector extends WebsphereCollector { + + private static final Log log = LogFactory.getLog(StatsDefaultCollector.class.getName()); + + protected abstract String[][] getAttributes(); + + public final void collect(AdminClient mServer) throws PluginException { + Stats stats = getStats(mServer, getObjectName()); + assert stats != null : getModuleName(); + if (stats == null) { + throw new PluginException("Stats not found"); + } + log.debug("[collect] '" + getModuleName() + "' stats: " + Arrays.asList(stats.getStatisticNames())); + collectStatCount(stats, getAttributes()); + setAvailability(true); + } +} Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ThreadPoolCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ThreadPoolCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/ThreadPoolCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -22,18 +22,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ - package org.hyperic.hq.plugin.websphere; -import javax.management.j2ee.statistics.Stats; +import javax.management.ObjectName; import org.hyperic.hq.product.PluginException; import com.ibm.websphere.management.AdminClient; -public class ThreadPoolCollector extends WebsphereCollector { +public class ThreadPoolCollector extends StatsDefaultCollector { - private static final String[][] ATTRS = { + private static final String[][] ATTRS = { { "PoolSize", "poolSize" }, { "CreateCount", "threadCreates" }, { "DestroyCount", "threadDestroys" }, @@ -41,37 +40,13 @@ }; protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); - - this.name = - newObjectNamePattern("type=ThreadPool," + - "name=" + getModuleName() + "," + - getProcessAttributes()); - - this.name = resolve(mServer, this.name); + ObjectName name = newObjectNamePattern("type=ThreadPool," + + "name=" + getModuleName() + "," + + getProcessAttributes()); + setObjectName(resolve(mServer, name)); } - public void collect() { - AdminClient mServer = getMBeanServer(); - if (mServer == null) { - return; - } - try { - Stats stats = getStats(mServer, this.name); - if (stats == null) { - //XXX certain threadpools have no stats, why? - Object o = getAttribute(mServer, this.name, "name"); - if (o != null) { - setAvailability(true); - } - } - else { - setAvailability(true); - collectStatCount(stats, ATTRS); - } - } catch (PluginException e) { - setAvailability(false); - setMessage(e.getMessage()); - } + protected String[][] getAttributes() { + return ATTRS; } } Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebappCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebappCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebappCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -22,49 +22,38 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ - package org.hyperic.hq.plugin.websphere; import org.hyperic.hq.product.PluginException; import com.ibm.websphere.management.AdminClient; +import javax.management.ObjectName; public class WebappCollector extends WebsphereCollector { protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); - String module = getModuleName(); int ix = module.indexOf('#'); if (ix == -1) { throw new PluginException("Malformed webapp name '" + module + "'"); } String app = module.substring(0, ix); - String war = module.substring(ix+1); + String war = module.substring(ix + 1); - this.name = - newObjectNamePattern("j2eeType=WebModule," + - "J2EEApplication=" + app + "," + - "name=" + war + "," + - getProcessAttributes()); - - this.name = resolve(mServer, this.name); + ObjectName name = newObjectNamePattern("j2eeType=WebModule," + + "J2EEApplication=" + app + "," + + "name=" + war + "," + + getProcessAttributes()); + + setObjectName(resolve(mServer, name)); } - public void collect() { - try{ - Object servlets = - getAttribute(getMBeanServer(), this.name, "servlets"); - - if (servlets == null) { - setAvailability(false); - } - else { - setAvailability(true); - } - } catch (PluginException e) { + public void collect(AdminClient mServer) throws PluginException { + Object servlets = getAttribute(mServer, getObjectName(), "servlets"); + if (servlets == null) { setAvailability(false); - setMessage(e.getMessage()); + } else { + setAvailability(true); } } } Deleted: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminMeasurementPlugin.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminMeasurementPlugin.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminMeasurementPlugin.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -1,9 +0,0 @@ -package org.hyperic.hq.plugin.websphere; - -public class WebsphereAdminMeasurementPlugin - extends WebsphereMeasurementPlugin { - - public boolean useJMX() { - return true; - } -} Deleted: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminServerCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminServerCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereAdminServerCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -1,67 +0,0 @@ -/* - * NOTE: This copyright does *not* cover user programs that use HQ - * program services by normal system calls through the application - * program interfaces provided as part of the Hyperic Plug-in Development - * Kit or the Hyperic Client Development Kit - this is merely considered - * normal use of the program, and does *not* fall under the heading of - * "derived work". - * - * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. - * This file is part of HQ. - * - * HQ is free software; you can redistribute it and/or modify - * it under the terms version 2 of the GNU General Public License as - * published by the Free Software Foundation. This program is distributed - * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -package org.hyperic.hq.plugin.websphere; - -import org.hyperic.hq.product.PluginException; - -import com.ibm.websphere.management.AdminClient; - -public class WebsphereAdminServerCollector extends WebsphereCollector { - - private double count(AdminClient mServer) throws Exception { - return WebsphereUtil.getMBeanCount(mServer, this.name, null); - } - - protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); - - this.name = - newObjectNamePattern("name=JVM," + - "type=JVM," + - "node=" + getNodeName()); - - try { - count(mServer); - } catch (Exception e) { - throw new PluginException("Invalid configuration: " + - e.getMessage()); - } - } - - public void collect() { - AdminClient mServer = getMBeanServer(); - if (mServer == null) { - return; - } - - setAvailability(true); - try { - setValue("NumJVMs", count(mServer)); - } catch (Exception e) { - //XXX - } - } -} Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -47,20 +47,28 @@ import com.ibm.websphere.management.AdminClient; import com.ibm.websphere.management.exception.ConnectorException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Set; +import javax.management.modelmbean.ModelMBeanAttributeInfo; public abstract class WebsphereCollector extends Collector { private static final Log log = LogFactory.getLog(WebsphereCollector.class.getName()); - protected ObjectName name; + private ObjectName name; private String domain; - protected ObjectName getObjectName() { + protected final ObjectName getObjectName() { return this.name; } - protected ObjectName newObjectNamePattern(String attrs) + protected final void setObjectName(ObjectName name) { + this.name=name; + } + + protected final ObjectName newObjectNamePattern(String attrs) throws PluginException { try { @@ -70,24 +78,25 @@ } } - protected String getServerAttributes() { + protected final String getServerAttributes() { return "J2EEServer=" + getServerName() + "," + "node=" + getNodeName(); } - protected String getProcessAttributes() { + protected final String getProcessAttributes() { return "process=" + getServerName() + "," + "node=" + getNodeName(); } - protected void init() throws PluginException { + protected final void init() throws PluginException { if(log.isDebugEnabled()){ - log.debug("[init] ("+getClass().getName()+") props="+getProperties()); + log.debug("[init] ("+getClass().getSimpleName()+") props="+getProperties()); } AdminClient mServer = getMBeanServer(); + assert mServer!=null; if(mServer==null) return; try { @@ -103,24 +112,21 @@ } } - protected void init(AdminClient mServer) - throws PluginException { + protected abstract void init(AdminClient mServer) throws PluginException; - } - - protected String getNodeName() { + private final String getNodeName() { return getProperties().getProperty(WebsphereProductPlugin.PROP_SERVER_NODE); } - protected String getServerName() { + protected final String getServerName() { return getProperties().getProperty(WebsphereProductPlugin.PROP_SERVER_NAME); } - protected String getModuleName() { + protected final String getModuleName() { return getProperties().getProperty("Module"); } - protected AdminClient getMBeanServer() { + private AdminClient getMBeanServer() { try { return WebsphereUtil.getMBeanServer(getProperties()); } catch (MetricUnreachableException e) { @@ -144,7 +150,7 @@ } } - protected Object getAttribute(AdminClient mServer, + protected final Object getAttribute(AdminClient mServer, ObjectName name, String attr) throws PluginException{ @@ -167,16 +173,16 @@ if (log.isDebugEnabled()) { log.debug("getAttribute(" + name + ", " + attr + "): " + e.getMessage(), e); - } + } throw new PluginException(e.getMessage()); } } - protected Stats getStats(AdminClient mServer, ObjectName name) throws PluginException { + protected final Stats getStats(AdminClient mServer, ObjectName name) throws PluginException { return (Stats)getAttribute(mServer, name, "stats"); } - protected double getStatCount(Statistic stat) { + private double getStatCount(Statistic stat) { if (stat instanceof CountStatistic) { return ((CountStatistic)stat).getCount(); } @@ -202,7 +208,7 @@ } } - protected double getStatCount(Stats stats, String metric) { + protected final double getStatCount(Stats stats, String metric) { Statistic stat = stats.getStatistic(metric); if (stat == null) { return MetricValue.VALUE_NONE; @@ -210,7 +216,7 @@ return getStatCount(stat); } - protected void collectStatCount(Stats stats, String[][] attrs) { + protected final void collectStatCount(Stats stats, String[][] attrs) { for (int i=0; i<attrs.length; i++) { String[] entry = attrs[i]; String statKey = entry[0]; @@ -223,11 +229,11 @@ } } - public MetricValue getValue(Metric metric, CollectorResult result) { + public final MetricValue getValue(Metric metric, CollectorResult result) { return super.getValue(metric, result); } - protected boolean collectStats(ObjectName name) throws PluginException { + protected final boolean collectStats(ObjectName name) throws PluginException { AdminClient mServer = getMBeanServer(); if (mServer == null) { return false; @@ -235,7 +241,7 @@ return collectStats(mServer, name); } - protected boolean collectStats(AdminClient mServer, ObjectName oname) throws PluginException { + private boolean collectStats(AdminClient mServer, ObjectName oname) throws PluginException { Stats stats = getStats(mServer, oname); if (stats == null) { setAvailability(false); @@ -257,4 +263,44 @@ return true; } + + public final void collect() { + String serverName = getProperties().getProperty("server.name"); + String module = getProperties().getProperty("Module"); + + if (log.isDebugEnabled()) { + log.debug("[collect] [" + serverName + "] class=" + this.getClass().getName()); + log.debug("[collect] [" + serverName + "] name=" + getObjectName()); + log.debug("[collect] [" + serverName + "] module=" + module); + log.debug("[collect] [" + serverName + "] getProperties=" + getProperties()); + } + setAvailability(false); + + if (getObjectName() == null) { + try { + init(); + } catch (PluginException ex) { + log.debug("[collect] [" + serverName + "] error!!! " + ex.getMessage()); + return; + } + } + + AdminClient mServer = getMBeanServer(); + if (mServer == null) { + return; + } + + setAvailability(true); + + try{ + collect(mServer); + } catch (PluginException e) { + setAvailability(false); + setMessage(e.getMessage()); + log.debug("[collect] [" + serverName + "] error:"+e.getMessage(),e); + } + log.debug("[collect] [" + serverName + "] end"); + } + + protected abstract void collect(AdminClient mServer) throws PluginException; } Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereProductPlugin.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereProductPlugin.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereProductPlugin.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -444,7 +444,7 @@ if (testIBMJDK) { VALID_JVM = System.getProperty("java.vm.vendor").toUpperCase().indexOf("IBM") != -1; if (!VALID_JVM) { - log.error("The WebSphere plugin needs a IBM JVM !!! " + log.debug("The WebSphere plugin needs a IBM JVM !!! " + "(agent jvm=" + System.getProperty("java.vm.vendor") + ")"); } } Modified: trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereServerCollector.java =================================================================== --- trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereServerCollector.java 2010-05-10 07:55:57 UTC (rev 14582) +++ trunk/plugins/websphere/src/org/hyperic/hq/plugin/websphere/WebsphereServerCollector.java 2010-05-10 21:55:32 UTC (rev 14583) @@ -29,6 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.management.ObjectName; import org.hyperic.hq.product.PluginException; import com.ibm.websphere.management.AdminClient; @@ -38,7 +39,6 @@ private static final Log log = LogFactory.getLog(WebsphereServerCollector.class.getName()); private boolean isJVM; - private String[][] attrs; //MBean Attribute -> legacy pmi name private static final String[][] TX_ATTRS = { @@ -57,76 +57,58 @@ }; protected void init(AdminClient mServer) throws PluginException { - super.init(mServer); - + String serverName = getProperties().getProperty("server.name"); String module = getProperties().getProperty("Module"); + log.debug("[init] [" + serverName + "] module=" + module); + String name; if (module.equals("jvmRuntimeModule")) { isJVM = true; - this.name = - newObjectNamePattern("name=JVM," + - "type=JVM," + - "j2eeType=JVM," + - getServerAttributes()); - - this.name = resolve(mServer, this.name); + name = "name=JVM,type=JVM,j2eeType=JVM"; + } else if (module.equals("transactionModule")) { + name = "type=TransactionService,j2eeType=JTAResource"; + } else if (module.equals("adminModule")) { + name = "name=JVM,type=JVM"; + } else { + throw new PluginException("Unexpected module '" + module + "'"); } - else if (module.equals("transactionModule")) { - this.name = - newObjectNamePattern("type=TransactionService," + - "j2eeType=JTAResource," + - getServerAttributes()); - try { - this.name = resolve(mServer, this.name); - this.attrs = TX_ATTRS; - } catch (PluginException e) { - //ok in the case of networkdeployer/nodeagent; - //where there is no TransactionService - log.debug(this.name + ": " + e.getMessage()); - this.name = null; - } - } + ObjectName on=newObjectNamePattern(name+","+getServerAttributes()); + on=resolve(mServer, on); + log.debug("[init] [" + serverName + "] name=" + on); + setObjectName(on); // check server properties. - Stats stats =(Stats) getStats(mServer, this.name); - + getStats(mServer, getObjectName()); } - public void collect() { - log.debug("[collect] name="+name); + public void collect(AdminClient mServer) throws PluginException { + if (getModuleName().equalsIgnoreCase("adminModule")) { + setValue("NumJVMs", count(mServer)); + } else { + Stats stats = (Stats) getStats(mServer, getObjectName()); - setAvailability(false); - - AdminClient mServer = getMBeanServer(); - if (mServer == null) { - return; + if (stats != null) { + if (isJVM) { + double total = getStatCount(stats, "HeapSize"); + double used = getStatCount(stats, "UsedMemory"); + setValue("totalMemory", total); + setValue("usedMemory", used); + setValue("freeMemory", total - used); + } else { + collectStatCount(stats, TX_ATTRS); + } + } else { + log.debug("no Stats"); + } } + } - setAvailability(true); - + private double count(AdminClient mServer) throws PluginException{ try { - if (this.name != null) { - Stats stats =(Stats) getStats(mServer, this.name); - - if (stats != null) { - if (isJVM) { - double total = getStatCount(stats, "HeapSize"); - double used = getStatCount(stats, "UsedMemory"); - setValue("totalMemory", total); - setValue("usedMemory", used); - setValue("freeMemory", total-used); - } - else { - collectStatCount(stats, this.attrs); - } - }else{ - log.debug("no Stats"); - } - } - } catch (PluginException e) { - setAvailability(false); - setMessage(e.getMessage()); + return WebsphereUtil.getMBeanCount(mServer, getObjectName(), null); + } catch (Exception ex) { + throw new PluginException(ex.getMessage(),ex); } } } |