modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java | 9 modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 85 ++++++-- modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/PluginStats.java | 61 +++++ modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 103 ++++++---- 4 files changed, 197 insertions(+), 61 deletions(-)
New commits: commit 1831a12d39873b64e0f4a07be6f274fc40c4a5cb Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 26 17:57:31 2011 +0200
Add some stats on processing times.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java index d86b365..5f350c0 100644 --- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java @@ -95,7 +95,9 @@ public class ASConnection {
InputStream inputStream = null; BufferedReader br=null; + long t1 = System.currentTimeMillis(); try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); @@ -135,11 +137,10 @@ public class ASConnection { else { outcome="- no response from server -"; } -// System.out.println("==> " + outcome); return operationResult; } else { - System.err.println("IS was null and code was " + responseCode); + log.error("IS was null and code was " + responseCode); }
@@ -152,6 +153,10 @@ public class ASConnection { } catch (IOException e) { e.printStackTrace(); // TODO: Customise this generated block } + long t2 = System.currentTimeMillis(); + PluginStats stats = PluginStats.getInstance(); + stats.incrementRequestCount(); + stats.addRequestTime(t2-t1); }
return null; diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java index ecb3fd6..de53386 100644 --- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java @@ -77,6 +77,8 @@ import java.util.Set; public class BaseComponent implements ResourceComponent, MeasurementFacet, ConfigurationFacet, DeleteResourceFacet, CreateChildResourceFacet, OperationFacet { + private static final String INTERNAL = "_internal:"; + private static final int INTERNAL_SIZE = INTERNAL.length(); final Log log = LogFactory.getLog(this.getClass());
ResourceContext context; @@ -149,31 +151,68 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi for (MeasurementScheduleRequest req : metrics) {
- Operation op = new ReadAttribute(pathToAddress(path),req.getName()); // TODO batching - //JsonNode obj = connection.executeRaw(op); - Result res = connection.execute(op, false); - if (!res.isSuccess()) - continue; - - String val = (String) res.getResult(); - - if (req.getDataType()== DataType.MEASUREMENT) { - if (!val.equals("no metrics available")) { // AS 7 returns this - try { - Double d = Double.parseDouble(val); - MeasurementDataNumeric data = new MeasurementDataNumeric(req,d); - report.addData(data); - } catch (NumberFormatException e) { - log.warn("Non numeric input for [" + req.getName() + "] : [" + val + "]"); + if (req.getName().startsWith(INTERNAL)) + processPluginStats(req,report); + else { + // Metrics from the application server + + Operation op = new ReadAttribute(pathToAddress(path),req.getName()); // TODO batching + //JsonNode obj = connection.executeRaw(op); + Result res = connection.execute(op, false); + if (!res.isSuccess()) + continue; + + String val = (String) res.getResult(); + + if (req.getDataType()== DataType.MEASUREMENT) { + if (!val.equals("no metrics available")) { // AS 7 returns this + try { + Double d = Double.parseDouble(val); + MeasurementDataNumeric data = new MeasurementDataNumeric(req,d); + report.addData(data); + } catch (NumberFormatException e) { + log.warn("Non numeric input for [" + req.getName() + "] : [" + val + "]"); + } } + } else if (req.getDataType()== DataType.TRAIT) { + MeasurementDataTrait data = new MeasurementDataTrait(req,val); + report.addData(data); } - } else if (req.getDataType()== DataType.TRAIT) { - MeasurementDataTrait data = new MeasurementDataTrait(req,val); - report.addData(data); } } }
+ /** + * Return internal statistics data + * @param req Schedule for the requested data + * @param report report to add th data to. + */ + private void processPluginStats(MeasurementScheduleRequest req, MeasurementReport report) { + + String name = req.getName(); + if (!name.startsWith(INTERNAL)) + return; + + name = name.substring(INTERNAL_SIZE); + + PluginStats stats = PluginStats.getInstance(); + MeasurementDataNumeric data; + Double val; + if (name.equals("mgmtRequests")) { + val= (double) stats.getRequestCount(); + } + else if (name.equals("requestTime")) { + val =(double) stats.getRequestTime(); + } + else if (name.equals("maxTime")) { + val = (double) stats.getMaxTime(); + } + else + val = Double.NaN; + + data = new MeasurementDataNumeric(req,val); + report.addData(data); + }
protected ASConnection getASConnection() { return connection; diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/PluginStats.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/PluginStats.java new file mode 100644 index 0000000..1a44dde --- /dev/null +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/PluginStats.java @@ -0,0 +1,61 @@ +package org.rhq.modules.plugins.jbossas7; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Singleton that keeps track of some statistics of this plugin + * @author Heiko W. Rupp + */ +public class PluginStats { + private static PluginStats ourInstance = new PluginStats(); + + AtomicLong requestCount = new AtomicLong(); + AtomicLong requestTime = new AtomicLong(); + private static final int FIFO_SIZE = 200; // Initial capacity + List<Long> maxTime = new ArrayList<Long>(FIFO_SIZE); + final Object lock = new Object(); + + + public static PluginStats getInstance() { + return ourInstance; + } + + private PluginStats() { + } + + public void incrementRequestCount() { + requestCount.incrementAndGet(); + } + + public void addRequestTime(long l) { + requestTime.addAndGet(l); + insertTime(l); + } + + public long getRequestCount() { + return requestCount.get(); + } + + public long getRequestTime() { + return requestTime.get(); + } + + public long getMaxTime() { + long max = 0; + synchronized (lock) { + for (Long i : maxTime) + if (i > max ) + max = i; + maxTime = new ArrayList<Long>(); + } + return max; + } + + private void insertTime(long time) { + synchronized (lock) { + maxTime.add(time); + } + } +} diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml index 75484c8..64251bc 100644 --- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml @@ -135,6 +135,18 @@ </operation>
+ <metric property="_internal:mgmtRequests" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="trendsup" description="Number of requests sent to the controller" + displayName="Number of management requests" + /> + <metric property="_internal:requestTime" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="trendsup" description="Total time for requests" units="milliseconds" + displayName="Time used for management requests"/> + <metric property="_internal:maxTime" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="dynamic" description="Max time for a request since last metric get" units="milliseconds" + displayName="Maximum request time"/> + + <server name="Profile" description="One profile in a domain" discovery="SubsystemDiscovery" @@ -237,6 +249,16 @@
<process-scan name="StandaloneAS" query="process|basename|match=^java.*,arg|org.jboss.as.standalone|match=.*"/>
+ <metric property="_internal:mgmtRequests" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="trendsup" description="Number of requests sent to the controller" + displayName="Number of management requests"/> + <metric property="_internal:requestTime" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="trendsup" description="Total time for requests" units="milliseconds" + displayName="Time used for management requests"/> + <metric property="_internal:maxTime" category="performance" dataType="measurement" defaultInterval="120000" + displayType="summary" measurementType="dynamic" description="Max time for a request since last metric get" units="milliseconds" + displayName="Maximum request time"/> +
<resource-configuration> <c:list-property name="schema-locations" displayName="Schema locations"> @@ -618,9 +640,9 @@ description="Should an archive validation error report fail the deployment. Default: true"/> <c:simple-property name="archive-validation-fail-on-warn" type="boolean" readOnly="true" default="false" description="Should an archive validation warning report fail the deployment. Default: false"/> - <c:simple-property name="cached-connection-manager-debug" type="boolean" readOnly="true" + <c:simple-property name="cached-connection-manager-debug" type="boolean" readOnly="true" default="false" description="enable/disable debug information logging for cached connection manager"/> - <c:simple-property name="cached-connection-manager-error" type="boolean" readOnly="true" + <c:simple-property name="cached-connection-manager-error" type="boolean" readOnly="true" default="false" description="enable/disable error information logging for cached connection manager"/> </resource-configuration>
@@ -937,15 +959,15 @@ <c:simple-property name="path" required="true" type="string" readOnly="false" description="The filesystem path."/> <c:simple-property name="relative-to" required="false" type="string" readOnly="false" description="The name of another previously named path, or of one of the standard paths provided by the system. - If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. - The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS - distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current - working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - - root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will - use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for - log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file - storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the - working area for individual server instances</li></ul>"/> +If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. +The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS +distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current +working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - +root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will +use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for +log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file +storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the +working area for individual server instances</li></ul>"/> </parameters> </operation> <resource-configuration> @@ -1001,15 +1023,15 @@ <c:simple-property name="path" required="true" type="string" readOnly="false" description="The filesystem path."/> <c:simple-property name="relative-to" required="false" type="string" readOnly="false" description="The name of another previously named path, or of one of the standard paths provided by the system. - If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. - The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS - distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current - working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - - root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will - use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for - log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file - storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the - working area for individual server instances</li></ul>"/> +If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. +The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS +distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current +working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - +root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will +use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for +log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file +storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the +working area for individual server instances</li></ul>"/> </parameters> </operation> <resource-configuration> @@ -1023,14 +1045,14 @@ <c:simple-property name="append" required="false" type="boolean" readOnly="true" description="Specify whether to append to the target file."/> <c:map-property name="file" description="null" > <c:simple-property name="relative-to" required="false" type="string" readOnly="true" description="The name of another previously named path, or of one of the standard paths - provided by the system. If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path - specified by this attribute. The standard paths provided by the system include:<ul><li>jboss.home - the root directory - of the JBoss AS distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current working - directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - root directory for an - individual server instance</li><li>jboss.server.data.dir - directory the server will use for persistent data file - storage</li><li>jboss.server.log.dir - directory the server will use for log file storage</li><li>jboss.server.tmp.dir - - directory the server will use for temporary file storage</li><li>jboss.domain.servers.dir - directory under which a host controller - will create the working area for individual server instances</li></ul>"/> +provided by the system. If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path +specified by this attribute. The standard paths provided by the system include:<ul><li>jboss.home - the root directory +of the JBoss AS distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current working +directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - root directory for an +individual server instance</li><li>jboss.server.data.dir - directory the server will use for persistent data file +storage</li><li>jboss.server.log.dir - directory the server will use for log file storage</li><li>jboss.server.tmp.dir - +directory the server will use for temporary file storage</li><li>jboss.domain.servers.dir - directory under which a host controller +will create the working area for individual server instances</li></ul>"/> <c:simple-property name="path" required="false" type="string" readOnly="true" description="The filesystem path."/> </c:map-property> <c:simple-property name="suffix" required="false" type="string" readOnly="true" description="Set the suffix string. The string is in a format which @@ -1072,15 +1094,15 @@ <c:simple-property name="path" required="true" type="string" readOnly="false" description="The filesystem path."/> <c:simple-property name="relative-to" required="false" type="string" readOnly="false" description="The name of another previously named path, or of one of the standard paths provided by the system. - If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. - The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS - distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current - working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - - root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will - use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for - log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file - storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the - working area for individual server instances</li></ul>"/> +If 'relative-to' is provided, the value of the 'path' attribute is treated as relative to the path specified by this attribute. +The standard paths provided by the system include:<ul><li>jboss.home - the root directory of the JBoss AS +distribution</li><li>user.home - user's home directory</li><li>user.dir - user's current +working directory</li><li>java.home - java installation directory</li><li>jboss.server.base.dir - +root directory for an individual server instance</li><li>jboss.server.data.dir - directory the server will +use for persistent data file storage</li><li>jboss.server.log.dir - directory the server will use for +log file storage</li><li>jboss.server.tmp.dir - directory the server will use for temporary file +storage</li><li>jboss.domain.servers.dir - directory under which a host controller will create the +working area for individual server instances</li></ul>"/> </parameters> </operation> <resource-configuration> @@ -1157,7 +1179,12 @@ <resource-configuration> <c:simple-property name="extends" required="false" type="string" readOnly="true" description="The parent security domain"/> <c:simple-property name="cache-type" required="false" type="string" readOnly="true" - description="Adds a cache to speed up authentication checks. Allowed values are 'default' to use simple map as the cache and 'infinispan' to use an Infinispan cache."/> + description="Adds a cache to speed up authentication checks. Allowed values are 'default' to use simple map as the cache and 'infinispan' to use an Infinispan cache."> + <c:property-options> + <c:option value="default"/> + <c:option value="infinispan"/> + </c:property-options> + </c:simple-property> </resource-configuration> </service>
commit 7a7c767c359f82a92056ad4a92ca8cc363ab9bcc Author: Heiko W. Rupp hwr@redhat.com Date: Wed May 25 13:21:43 2011 +0200
Get availability by checking if the resource is readable.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java index f35720e..ecb3fd6 100644 --- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java @@ -93,8 +93,11 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi * @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability() */ public AvailabilityType getAvailability() { - // TODO supply real implementation - return AvailabilityType.UP; + + ReadResource op = new ReadResource(pathToAddress(path)); + Result res = connection.execute(op); + + return res.isSuccess()? AvailabilityType.UP: AvailabilityType.DOWN; }
@@ -179,6 +182,7 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi
protected String getPath() { return path; }
+ // TODO this needs completeion and a big fat refactoring public Configuration loadResourceConfiguration() throws Exception { ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition(); // String myPath = getResultingPath();