Command-line Tool to find Java Heap Size and Memory Used (Linux)?

Jasper picture Jasper · Oct 9, 2012 · Viewed 607.2k times · Source

Is there a Command-line Tool (Linux) to check Heap Size (and Used Memory) of a Java Application?

I have tried through jmap. But it gives info. about internal memory areas like Eden/ PermGen etc., which is not useful to me.

I am looking for something like:

  • Max Memory: 1GB
  • Min Memory: 256 MB
  • Heap Memory: 700 MB
  • Used Memory: 460 MB

That's all. I know that I can see this in JConsole etc., but I need a command-line tool (can't enable JMX etc.)

Do you know any such a tool/ command?

Answer

farmer1992 picture farmer1992 · Oct 9, 2012

Each Java process has a pid, which you first need to find with the jps command.

Once you have the pid, you can use jstat -gc [insert-pid-here] to find statistics of the behavior of the garbage collected heap.

  • jstat -gccapacity [insert-pid-here] will present information about memory pool generation and space capabilities.

  • jstat -gcutil [insert-pid-here] will present the utilization of each generation as a percentage of its capacity. Useful to get an at a glance view of usage.

See jstat docs on Oracle's site.