5 Replies Latest reply on Nov 20, 2009 10:19 AM by jay shaughnessy

    JVM Free Memory, JVM Max Memory and JVM Total Memory metrics

    rafael liu Newbie

      Jopr has these metrics do these metrics correspond to the methods:

      JVM Free Memory = Runtime.freeMemory()
      JVM Max Memory = Runtime.maxMemory()
      JVM Total Memory = Runtime.totalMemory()


      ?

      Thanks

        • 1. Re: JVM Free Memory, JVM Max Memory and JVM Total Memory met
          mazz Master

          Depends on which metrics you are looking at exactly. Plugins define things however they want. For examle, The JMX plugin has JVM resources that drill down to the actual platform MBeans with memory info. Other plugins use those Runtime methods you mention to report memory data.

          For example, I think the RHQ Agent plugin has the agent resource itself expose those 3 things. But there are also child VM resources under that agent resource that expose the actual platform MBean memory data, too.

          So, can you be more specific about where you see those metric definitions? What resource are you looking at?

          • 2. Re: JVM Free Memory, JVM Max Memory and JVM Total Memory met
            rafael liu Newbie

            I'm talking about JBoss AS plugin. Going down to the point, here is what I see in my Sumary:

            JVM Free Memory: 361,6MB
            JVM Max Memory: 1,7778GB
            JVM Total Memory: 781MB

            I seems the above mentioned methods are being used to mesure these but freeMemory() actually doesn't give us the amount of free memory the JVM can allocate. AFAIK it gives us how much memory is free until JVM have to allocate more memory (increasing totalMemory).

            Besides the name be misleading (only a "translation" of the method's prototype) it's not much useful. Instead showing the actual amount of free-to-allocate memory would be nicer (freeMem + (maxMem - totalMem)).

            I get this felling because numbers don't fit. Suppose my 512MB of non-heap reach and there's no OOM.. :

            361,6MB + 781MB + 512MB = 1654MB < 1,7778GB

            Is that right?

            • 3. Re: JVM Free Memory, JVM Max Memory and JVM Total Memory met
              mazz Master

              Here is the plugin descriptor for the jboss-as plugin for those metrics:

              <metric property="jboss.system:type=ServerInfo:FreeMemory" displayName="JVM Free Memory" displayType="summary"
               description="The amount of free memory for the JVM this app server instance is running on"
               defaultInterval="300000" defaultOn="true" category="utilization" units="bytes"/>
              
               <metric property="jboss.system:type=ServerInfo:MaxMemory" displayName="JVM Max Memory"
               description="The amount of max memory for the JVM this app server instance is running on"
               defaultInterval="1800000" defaultOn="true" category="utilization" units="bytes"/>
              
               <metric property="jboss.system:type=ServerInfo:TotalMemory" displayName="JVM Total Memory" displayType="summary"
               description="The amount of total memory for the JVM this app server instance is running on"
               defaultInterval="300000" defaultOn="true" category="utilization" units="bytes"/>
              


              As you can see, these are coming from JBossAS's MBean called "jboss.system:type=ServerInfo" - its attributes FreeMemory, MaxMemory, and TotalMemory. You would have to look at the JBossAS server source code or its docs to see what those MBean attributes are really saying, but I suspect they are the Runtime object's method calls like you mentioned earlier.

              If that's true, those numbers do not include any non-heap memory space. Those are only heap memory values. You need to use the platform MBeans to get non-heap memory metrics as well.

              The JMX plugin provides these metrics, and they are added to the JBossAS Server via the child resource "JBossAS JVM" - from the jboss-as plugin::

              <server name="JBoss AS JVM"
               description="JVM of the JBossAS"
               sourcePlugin="JMX"
               sourceType="JMX Server"
               discovery="org.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent"
               class="org.rhq.plugins.jmx.JMXServerComponent"
               singleton="true"/>
              


              So under your JBossAS Server resource, you should see a JBoss AS JVM resource. It has children that represent the platform MBeans that give you non-heap and heap memory metrics. From the JMX plugin, you can see their definitions:

              <service name="VM Memory System" discovery="MBeanResourceDiscoveryComponent" class="MBeanResourceComponent"
               description="The memory system of the Java virtual machine including both the heap and non-heap memory."
               createDeletePolicy="neither" singleton="true">
              
               <plugin-configuration>
               <c:simple-property name="objectName" readOnly="true" default="java.lang:type=Memory"/>
               <c:simple-property name="nameTemplate" default="Memory Subsystem"/>
               </plugin-configuration>
              
               <operation name="gc" displayName="Run Garbage Collection" description="Runs the garbage collector."/>
              
               <metric displayName="Heap Usage"
               property="{HeapMemoryUsage.used}"
               displayType="summary"
               description="Current heap memory usage"
               units="bytes"/>
               <metric displayName="Heap Committed"
               property="{HeapMemoryUsage.committed}"
               displayType="summary"
               description="Current heap memory allocated. This amount of memory is guaranteed for the Java virtual machine to use"
               units="bytes"/>
               <metric displayName="Non-Heap Usage"
               property="{NonHeapMemoryUsage.used}"
               displayType="summary"
               description="Current memory usage outside the heap"
               units="bytes"/>
               <metric displayName="Non-Heap Committed"
               property="{NonHeapMemoryUsage.committed}"
               displayType="summary"
               description="Current memory allocated outside the heap. This amount of memory is guaranteed for the Java virtual machine to use"
               units="bytes"/>
               <metric displayName="Objects Pending Finalization"
               property="ObjectPendingFinalizationCount"
               description="The approximate number of objects for which finalization is pending."/>
               <metric displayName="Heap Initial Size"
               property="{HeapMemoryUsage.init}"
               displayType="summary"
               dataType="trait"
               description="The amount of heap that the Java virtual machine initially requests from the operating system"
               units="bytes"/>
               <metric displayName="Heap Maximum Size"
               property="{HeapMemoryUsage.max}"
               displayType="summary"
               dataType="trait"
               description="Maximum amount of heap that can be used for memory management. This amount of memory is not guaranteed to be available if it is greater than the amount of committed memory. The Java virtual machine may fail to allocate memory even if the amount of used memory does not exceed this maximum size."
               units="bytes"/>
               <metric displayName="Non-Heap Initial Size"
               property="{NonHeapMemoryUsage.init}"
               displayType="summary"
               dataType="trait"
               description="The amount of non-heap memory that the Java virtual machine initially requests from the operating system"
               units="bytes"/>
               <metric displayName="Non-Heap Maximum Size"
               property="{NonHeapMemoryUsage.max}"
               displayType="summary"
               dataType="trait"
               description="Maximum amount of non-heap memory that can be used for memory management. This amount of memory is not guaranteed to be available if it is greater than the amount of committed memory. The Java virtual machine may fail to allocate memory even if the amount of used memory does not exceed this maximum size."
               units="bytes"/>
              
              


              • 4. Re: JVM Free Memory, JVM Max Memory and JVM Total Memory met
                rafael liu Newbie

                Thanks for the info mazz,

                my whole point is that freeMem isn't useful.. For example, what freeMem < 200MB means??

                Creating custom metrics would be great for that matter. There could be a groovy script expression that would evaluate this freeMem + (maxMem - totalMem).

                • 5. Re: JVM Free Memory, JVM Max Memory and JVM Total Memory met
                  jay shaughnessy Expert

                  Note that the JVM metrics don't actually provide anything simple for alerting against a low memory situation. What we really need to add here is something like a percentageFree metric that is a calculation of the other provided metrics. Something like (Used/Max*100).