5 Replies Latest reply on Nov 27, 2012 1:02 PM by nikhilmone

    How Can I monitoring java heap with jstat?

    erasmomarciano

      I'd like to know the heap memory usage with jstat as in jmx.console

       

      exmaple

       

      Heap size 4G

       

      Heap memory usage 3,75G

        • 1. Re: How Can I monitoring java heap with jstat?
          wdfink

          jstat is a console tool to monitor the JVM heap and GC.

          See the documentation

           

          I often use 'jstat -gc PID <intervall>'

          • 2. Re: How Can I monitoring java heap with jstat?
            rhusar

            You may want to use jmap. Here is an example that I like to use:

             

            [rhusar@rhusar as-master]$ jps -l
            18374 org.jetbrains.idea.maven.server.RemoteMavenServer
            18281 com.intellij.idea.Main
            21105 sun.tools.jps.Jps
            [rhusar@rhusar as-master]$ jmap -histo:live 18281 | head
            
             num     #instances         #bytes  class name
            ----------------------------------------------
               1:        176916       24493688  <constMethodKlass>
               2:        176916       24077408  <methodKlass>
               3:         22170       23879160  <constantPoolKlass>
               4:         22170       18736416  <instanceKlassKlass>
               5:        139987       13574248  [C
               6:        198198       12992576  [B
               7:         18624       12898400  <constantPoolCacheKlass>
            

             

            Otherwise jconsole is great if you want UI.

            • 3. Re: How Can I monitoring java heap with jstat?
              erasmomarciano

              Hi thanks for reply

               

              I know jconsole and other strument for calcolate the sum Heap.

               

              I usally i run kill -3 on the PID

               

               

              [rhusar@rhusar as-master]$ jmap -histo:live 18281 | head

              num     #instances         #bytes  class name
              ----------------------------------------------
                 1:        176916       24493688  <constMethodKlass>
                 2:        176916       24077408  <methodKlass>
                 3:         22170       23879160  <constantPoolKlass>
                 4:         22170       18736416  <instanceKlassKlass>
                 5:        139987       13574248  [C
                 6:        198198       12992576  [B
                 7:         18624       12898400  <constantPoolCacheKlass>

               

              For calculate the sum Heap i have additional the point 1 2 ..7 ? 

              I have a result in byte

               

              thank

              • 4. Re: How Can I monitoring java heap with jstat?
                rhusar

                AFAIK yes, summing up all the bytes should give you the total heap as well (obviously, dont paste it through head command then as I did in the example above).

                 

                jstat will tell you the totals in each generation, which is very useful but if you want to quickly see which objects are holding up the memory jmap comes in handy.

                • 5. Re: How Can I monitoring java heap with jstat?
                  nikhilmone

                  You can also try below command that gives you detail of entire memory usage :

                   

                  =========================================

                  $ jmap -heap <Proces ID of your JVM>

                  Attaching to process ID 29696, please wait...

                  Debugger attached successfully.

                  Server compiler detected.

                  JVM version is 20.6-b01

                   

                  using thread-local object allocation.

                  Parallel GC with 4 thread(s)

                   

                  Heap Configuration:

                     MinHeapFreeRatio = 40

                     MaxHeapFreeRatio = 70

                     MaxHeapSize      = 1367343104 (1304.0MB)

                     NewSize          = 1310720 (1.25MB)

                     MaxNewSize       = 17592186044415 MB

                     OldSize          = 5439488 (5.1875MB)

                     NewRatio         = 2

                     SurvivorRatio    = 8

                     PermSize         = 21757952 (20.75MB)

                     MaxPermSize      = 268435456 (256.0MB)

                   

                  Heap Usage:

                  PS Young Generation

                  Eden Space:

                     capacity = 341966848 (326.125MB)

                     used     = 298634744 (284.80028533935547MB)

                     free     = 43332104 (41.32471466064453MB)

                     87.32856583805457% used

                  From Space:

                     capacity = 56885248 (54.25MB)

                     used     = 56854136 (54.22032928466797MB)

                     free     = 31112 (0.02967071533203125MB)

                     99.94530743717598% used

                  To Space:

                     capacity = 56885248 (54.25MB)

                     used     = 0 (0.0MB)

                     free     = 56885248 (54.25MB)

                     0.0% used

                  PS Old Generation

                     capacity = 910884864 (868.6875MB)

                     used     = 71342136 (68.03716278076172MB)

                     free     = 839542728 (800.6503372192383MB)

                     7.832179325794572% used

                  PS Perm Generation

                     capacity = 71303168 (68.0MB)

                     used     = 71145280 (67.84942626953125MB)

                     free     = 157888 (0.15057373046875MB)

                     99.77856804342831% used

                  =========================================

                  1 of 1 people found this helpful