[jboss-cvs] JBossAS SVN: r77041 - 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:21:05 EDT 2008
Author: pferraro
Date: 2008-08-13 17:21:05 -0400 (Wed, 13 Aug 2008)
New Revision: 77041
Added:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java
Log:
[JBAS-5668] LoadMetricSource impl for gathering VM metrics
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,98 @@
+/*
+ * 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.OperatingSystemMXBean;
+
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Uses {@link OperatingSystemMXBean#getSystemLoadAverage} to calculate average system load.
+ * Only supported on Java 1.6 or later.
+ *
+ * @author Paul Ferraro
+ */
+public class AverageSystemLoadMetric extends AbstractLoadMetric
+{
+ private static final String SYSTEM_LOAD_AVERAGE = "SystemLoadAverage";
+
+ private final OperatingSystemLoadMetricSource source;
+ private final Logger log = Logger.getLogger(this.getClass());
+
+ /**
+ * Create a new SystemLoadMetric.
+ *
+ * @param registration
+ */
+ public AverageSystemLoadMetric(OperatingSystemLoadMetricSource source)
+ {
+ this.source = source;
+
+ try
+ {
+ MBeanInfo info = this.source.getServer().getMBeanInfo(source.getOperatingSystemObjectName());
+
+ boolean exists = false;
+
+ for (MBeanAttributeInfo attribute: info.getAttributes())
+ {
+ if (SYSTEM_LOAD_AVERAGE.equals(attribute.getName()))
+ {
+ exists = true;
+ break;
+ }
+ }
+
+ if (exists)
+ {
+ this.source.add(this);
+ }
+ else
+ {
+ this.log.warn(OperatingSystemMXBean.class.getName() + "." + SYSTEM_LOAD_AVERAGE + " is only supported on Java 1.6 or later");
+ }
+ }
+ catch (JMException e)
+ {
+ // This should not happen on a system mxbean
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+ */
+ public double getMetric() throws JMException
+ {
+ MBeanServer server = this.source.getServer();
+ ObjectName name = this.source.getOperatingSystemObjectName();
+
+ return ((Double) server.getAttribute(name, SYSTEM_LOAD_AVERAGE)).doubleValue();
+ }
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,59 @@
+/*
+ * 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.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class HeapMemoryUsageLoadMetric extends SingleLoadMetricSource
+{
+ private final MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
+
+ /**
+ * Create a new SystemLoadBalanceMetricProvider.
+ *
+ * @param registration
+ */
+ public HeapMemoryUsageLoadMetric(LoadMetricSourceRegistration registration)
+ {
+ super(registration);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+ */
+ public double getMetric()
+ {
+ MemoryUsage usage = this.bean.getHeapMemoryUsage();
+
+ return ((double) usage.getUsed()) / usage.getMax();
+ }
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,71 @@
+/*
+ * 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 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 class OperatingSystemLoadMetricSource extends AbstractLoadMetricSource
+{
+ private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ private final ObjectName name;
+
+ /**
+ * Create a new OperatingSystemLoadMetricSource.
+ *
+ * @param registration
+ */
+ public OperatingSystemLoadMetricSource(LoadMetricSourceRegistration registration)
+ {
+ super(registration);
+
+ try
+ {
+ this.name = ObjectName.getInstance(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ // Should never happen given this is a platform mxbean
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ObjectName getOperatingSystemObjectName()
+ {
+ return this.name;
+ }
+
+ public MBeanServer getServer()
+ {
+ return this.server;
+ }
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,102 @@
+/*
+ * 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.util.Set;
+import java.util.TreeSet;
+
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * Uses {@link com.sun.management.OperatingSystemMXBean} to determine system memory usage.
+ *
+ * @author Paul Ferraro
+ */
+public class SystemMemoryUsageLoadMetric extends AbstractLoadMetric
+{
+ private static final String FREE_MEMORY = "FreePhysicalMemorySize";
+ private static final String TOTAL_MEMORY = "TotalPhysicalMemorySize";
+
+ private final OperatingSystemLoadMetricSource source;
+ private final Logger log = Logger.getLogger(this.getClass());
+
+ /**
+ * Create a new SystemMemoryUsageLoadMetric.
+ *
+ * @param registration
+ */
+ public SystemMemoryUsageLoadMetric(OperatingSystemLoadMetricSource source)
+ {
+ this.source = source;
+
+ try
+ {
+ MBeanInfo info = this.source.getServer().getMBeanInfo(source.getOperatingSystemObjectName());
+
+ Set<String> missingAttributes = new TreeSet<String>();
+
+ missingAttributes.add(FREE_MEMORY);
+ missingAttributes.add(TOTAL_MEMORY);
+
+ for (MBeanAttributeInfo attribute: info.getAttributes())
+ {
+ missingAttributes.remove(attribute.getName());
+ }
+
+ if (missingAttributes.isEmpty())
+ {
+ this.source.add(this);
+ }
+ else
+ {
+ this.log.warn(this.source.getOperatingSystemObjectName() + " is missing the following attributes required by this metric: " + missingAttributes);
+ }
+ }
+ catch (JMException e)
+ {
+ // This should not happen on a system mxbean
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+ */
+ public double getMetric() throws JMException
+ {
+ MBeanServer server = this.source.getServer();
+ ObjectName name = this.source.getOperatingSystemObjectName();
+
+ long free = ((Long) server.getAttribute(name, FREE_MEMORY)).longValue();
+ long total = ((Long) server.getAttribute(name, FREE_MEMORY)).longValue();
+
+ return ((double) free) / total;
+ }
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,55 @@
+/*
+ * 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.lang.management.ThreadMXBean;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ThreadCountLoadMetric extends SingleLoadMetricSource
+{
+ private ThreadMXBean bean = ManagementFactory.getThreadMXBean();
+
+ /**
+ * Create a new ThreadCountLoadMetric.
+ *
+ * @param registration
+ */
+ public ThreadCountLoadMetric(LoadMetricSourceRegistration registration)
+ {
+ super(registration);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+ */
+ public double getMetric()
+ {
+ return this.bean.getThreadCount();
+ }
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java 2008-08-13 21:21:05 UTC (rev 77041)
@@ -0,0 +1,56 @@
+/*
+ * 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.lang.management.RuntimeMXBean;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class UptimeLoadMetric extends SingleLoadMetricSource
+{
+ private RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
+
+ /**
+ * Create a new RuntimeMetric.
+ *
+ * @param registration
+ */
+ public UptimeLoadMetric(LoadMetricSourceRegistration registration)
+ {
+ super(registration);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+ */
+ public double getMetric()
+ {
+ return this.runtimeBean.getUptime();
+ }
+}
More information about the jboss-cvs-commits
mailing list