[jboss-cvs] JBossAS SVN: r77039 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 13 17:18:59 EDT 2008


Author: pferraro
Date: 2008-08-13 17:18:59 -0400 (Wed, 13 Aug 2008)
New Revision: 77039

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
Log:
[JBAS-5666] LoadMetricSource impl for gather JBossWeb request metrics

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class BusyConnectorsLoadMetric extends AbstractLoadMetric
+{
+   private final ThreadPoolLoadMetricSource source;
+   
+   public BusyConnectorsLoadMetric(ThreadPoolLoadMetricSource source)
+   {
+      this.source = source;
+      
+      source.add(this);
+   }
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    */
+   public double getMetric() throws JMException
+   {
+      int busy = 0;
+      
+      MBeanServer server = this.source.getServer();
+      
+      for (ObjectName threadPoolName: this.source.getObjectNames())
+      {
+         busy += ((Integer) server.getAttribute(threadPoolName, "currentThreadsBusy")).intValue();
+      }
+      
+      return busy;
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import java.lang.management.ManagementFactory;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public abstract class ObjectNamePatternLoadMetricSource extends AbstractLoadMetricSource
+{
+   private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+   private volatile ObjectName objectNamePattern;
+   private transient Set<ObjectName> objectNames;
+   
+   protected ObjectNamePatternLoadMetricSource(LoadMetricSourceRegistration registration)
+   {
+      super(registration);
+      
+      try
+      {
+         this.objectNamePattern = ObjectName.getInstance(this.defaultObjectNamePattern());
+      }
+      catch (MalformedObjectNameException e)
+      {
+         // Won't happen
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected abstract String defaultObjectNamePattern();
+   
+   /**
+    * Get the objectNamePattern.
+    * 
+    * @return the objectNamePattern.
+    */
+   public ObjectName getObjectNamePattern()
+   {
+      return this.objectNamePattern;
+   }
+
+   /**
+    * Set the objectNamePattern.
+    * 
+    * @param objectNamePattern The objectNamePattern to set.
+    */
+   public void setObjectNamePattern(ObjectName objectNamePattern)
+   {
+      this.objectNamePattern = objectNamePattern;
+   }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.AbstractLoadMetricSource#open()
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   public void open()
+   {
+      this.objectNames = this.server.queryMBeans(this.objectNamePattern, null);
+   }
+   
+   public MBeanServer getServer()
+   {
+      return this.server;
+   }
+   
+   public Set<ObjectName> getObjectNames()
+   {
+      return this.objectNames;
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ReceiveTrafficLoadMetric extends AbstractLoadMetric
+{
+   private static final String RECEIVE_COUNT = "bytesReceived";
+   
+   private final RequestProcessorLoadMetricSource source;
+   
+   public ReceiveTrafficLoadMetric(RequestProcessorLoadMetricSource source)
+   {
+      this.source = source;
+   }
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    */
+   public double getMetric() throws JMException
+   {
+      MBeanServer server = this.source.getServer();
+      
+      long bytes = 0;
+      
+      for (ObjectName name: this.source.getObjectNames())
+      {
+         bytes += ((Long) server.getAttribute(name, RECEIVE_COUNT)).longValue();
+      }
+      
+      return bytes;
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class RequestCountLoadMetric extends AbstractLoadMetric
+{
+   private static final String REQUEST_COUNT = "requestCount";
+   
+   private final RequestProcessorLoadMetricSource source;
+   
+   public RequestCountLoadMetric(RequestProcessorLoadMetricSource source)
+   {
+      this.source = source;
+   }
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    */
+   public double getMetric() throws JMException
+   {
+      MBeanServer server = this.source.getServer();
+      
+      int count = 0;
+      
+      for (ObjectName name: this.source.getObjectNames())
+      {
+         count += ((Integer) server.getAttribute(name, REQUEST_COUNT)).intValue();
+      }
+      
+      return count;
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class RequestProcessorLoadMetricSource extends ObjectNamePatternLoadMetricSource
+{
+   /**
+    * Create a new GlobalRequestProcessorLoadMetricSource.
+    * 
+    * @param registration
+    */
+   public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration)
+   {
+      super(registration);
+   }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.ObjectNamePatternLoadMetricSource#defaultObjectNamePattern()
+    */
+   @Override
+   protected String defaultObjectNamePattern()
+   {
+      return "Catalina:type=GlobalRequestProcessor,name=*";
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SendTrafficLoadMetric extends AbstractLoadMetric
+{
+   private static final String SEND_COUNT = "bytesSent";
+   
+   private final RequestProcessorLoadMetricSource source;
+   
+   public SendTrafficLoadMetric(RequestProcessorLoadMetricSource source)
+   {
+      this.source = source;
+   }
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    */
+   public double getMetric() throws JMException
+   {
+      MBeanServer server = this.source.getServer();
+      
+      long bytes = 0;
+      
+      for (ObjectName name: this.source.getObjectNames())
+      {
+         bytes += ((Long) server.getAttribute(name, SEND_COUNT)).longValue();
+      }
+      
+      return bytes;
+   }
+}

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java	2008-08-13 21:18:59 UTC (rev 77039)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+
+/**
+ * @author Paul Ferraro
+ */
+public class ThreadPoolLoadMetricSource extends ObjectNamePatternLoadMetricSource
+{
+   /**
+    * Create a new ThreadPoolLoadMetricSource.
+    * 
+    * @param registration
+    */
+   public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration)
+   {
+      super(registration);
+   }
+
+   protected String defaultObjectNamePattern()
+   {
+      return "Catalina:type=ThreadPool,name=*";
+   }
+}




More information about the jboss-cvs-commits mailing list