geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r561094 - /geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java
Date Mon, 30 Jul 2007 19:05:20 GMT
Author: dwoods
Date: Mon Jul 30 12:05:20 2007
New Revision: 561094

URL: http://svn.apache.org/viewvc?view=rev&rev=561094
Log:
GERONIMO-2878 JVM stats exposed through JMX are incorrect

Modified:
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java?view=diff&rev=561094&r1=561093&r2=561094
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/management/impl/JVMImpl.java
Mon Jul 30 12:05:20 2007
@@ -17,6 +17,10 @@
 
 package org.apache.geronimo.j2ee.management.impl;
 
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+import java.lang.management.RuntimeMXBean;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Date;
@@ -34,6 +38,7 @@
 import org.apache.geronimo.management.StatisticsProvider;
 import org.apache.geronimo.management.geronimo.JVM;
 import org.apache.geronimo.management.stats.BoundedRangeStatisticImpl;
+import org.apache.geronimo.management.stats.CountStatisticImpl;
 import org.apache.geronimo.management.stats.JVMStatsImpl;
 import org.apache.geronimo.system.logging.SystemLog;
 
@@ -151,26 +156,38 @@
     }
 
     public Stats getStats() {
-        BoundedRangeStatisticImpl heap;
-        if(stats == null) {
+        RuntimeMXBean runmxbean = ManagementFactory.getRuntimeMXBean();
+        MemoryMXBean memmxbean = ManagementFactory.getMemoryMXBean();
+        MemoryUsage memUsage = memmxbean.getHeapMemoryUsage();
+        CountStatisticImpl upTime;
+        BoundedRangeStatisticImpl heapSize;
+        
+        if (stats == null) {
             stats = new JVMStatsImpl();
-            long start = kernel.getBootTime().getTime();
-            stats.getUpTimeImpl().setCount(start);
-            stats.getUpTimeImpl().setStartTime(start);
-            heap = stats.getHeapSizeImpl();
-            heap.setStartTime(start);
-            heap.setBounds(0, runtime.totalMemory());
-            heap.setCurrent(heap.getUpperBound() - runtime.freeMemory());
-            heap.setLowWaterMark(heap.getCurrent());
-            heap.setHighWaterMark(heap.getCurrent());
+            // setup UpTime CountStatistic
+            upTime = stats.getUpTimeImpl();
+            upTime.setStartTime(runmxbean.getStartTime());
+            upTime.setCount(runmxbean.getUptime());
+            // setup Heap BoundedRangeStatistic
+            heapSize = stats.getHeapSizeImpl();
+            heapSize.setStartTime(runmxbean.getStartTime());
+            heapSize.setBounds(0, memUsage.getMax());
+            heapSize.setCurrent(memUsage.getUsed());
+            heapSize.setLowWaterMark(memUsage.getUsed());
+            heapSize.setHighWaterMark(memUsage.getUsed());
         } else {
-            heap = stats.getHeapSizeImpl();
-            heap.setBounds(0, runtime.totalMemory());
-            heap.setCurrent(heap.getUpperBound() - runtime.freeMemory());
-        }
-        long now = System.currentTimeMillis();
-        stats.getUpTimeImpl().setLastSampleTime(now);
-        heap.setLastSampleTime(now);
+            // update UpTime CountStatistic
+            upTime = stats.getUpTimeImpl();
+            upTime.setCount(runmxbean.getUptime());
+            // update Heap BoundedRangeStatistic
+            heapSize = stats.getHeapSizeImpl();
+            heapSize.setBounds(0, memUsage.getMax());
+            heapSize.setCurrent(memUsage.getUsed());
+        }
+        long now = upTime.getStartTime() + upTime.getCount();
+        upTime.setLastSampleTime(now);
+        heapSize.setLastSampleTime(now);
+
         return stats;
     }
 



Mime
View raw message