Can I check heap usage of a running JVM from the commandline, I mean the actual usage rather than the max amount allocated with Xmx.
I need it to be commandline because I don't have access to a windowing environment, and I want script based on the value , the application is running in Jetty Application server
All procedure at once. Based on @Till Schäfer answer.
In KB...
In MB...
"Awk sum" reference:
Thanks!
NOTE: Works to OpenJDK!
FURTHER QUESTION: Wrong information?
If you check memory usage with the
ps
command, you will see that the java process consumes much more...If you start execution with gc logging turned on you get the info on file. Otherwise 'jmap -heap ' will give you what you want. See the jmap doc page for more.
Please note that
jmap
should not be used in a production environment unless absolutely needed as the tool halts the application to be able to determine actual heap usage. Usually this is not desired in a production environment.You can use jstat, like :
Full docs here : http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstat.html
For Java 8 you can use the following command line to get the heap space utilization in kB:
The command basically sums up:
You may also want to include the metaspace and the compressed class space utilization. In this case you have to add a[10] and a[12] to the awk sum.