To find JVM memory usage in shell console

i need to find memory usage by JVM in shell prompt,

i tried with

pidVal=$( ps -ef | grep "/opt/bea2/jrockit/bin/java -jrockit" | grep -v grep | awk -F' ' '{print $2}' | tr "\n" "," | cut -d ',' -f1 )
 
top -b -n 1 | grep $pidVal

this will just give cpu usage and ram... How do i find the actual memory usage of JVM,

from Server monitoring console (Hyperic)( HQ health) it will show consumption in real time. i need to find the same at shell prompt. Any help wil be deeply appreciated.

Have a look at jstat.

What OS: Linux, Solaris, ... other?

On Linux this will give you what the OS sees as resident for all java processes (use -ovsz for virtual):

ps -orss= -p$(/sbin/pidof java)

With jrockit you could also use jrcmd <pid> print_memusage for more detailed info.

i tried the command (i am using linux)

below which one is memory allocated and memory free or used?

# ps -orss= -p $(/sbin/pidof java)
597712
105300
47364
143556
1441024
4416636
1080604
3922112
132776
118644
]# jrcmd $pidVal print_memusage
9457:
Total mapped                  2864288KB           (reserved=1325008KB)
-              Java heap      1048576KB           (reserved=0KB)
-              GC tables        35084KB
-          Thread stacks        25204KB           (#threads=56)
-          Compiled code      1048576KB           (used=15421KB)
-               Internal         1864KB
-                     OS       236040KB
-                  Other       327120KB
-            Classblocks         7936KB           (malloced=7755KB #20432)
-        Java class data       132864KB           (malloced=132259KB #92498 in 20432 classes)
- Native memory tracking         1024KB           (malloced=125KB #10)

in the HQ monitor console its showing as

JVM Memory
% Used:31Free:5.3 GBTotal Allocated:7.7 GBMax Allocation:7.7 GB

so its not tallying up :frowning:

It seems that you have 10 java processes. If HQ monitor is reporting the memory usage for a single JVM, you could run:

ps -opid,rss,vsz -p $(/sbin/pidof java)

... and there should be a pid, with VSZ of about 7.7. You should compare its RSS to what the HQ monitor shows.