Eric V
Eric V

Reputation: 1170

Getting total used memory of a running JVM under Linux

I'm looking for an efficient way to measure the memory used by a running jvm. A single command line with the pid of my jvm returning a reliable value of the consummed size of the memory.

Thx

Upvotes: 2

Views: 11271

Answers (1)

Joachim H. Skeie
Joachim H. Skeie

Reputation: 1903

You can run

ps aux | grep java

This will show you the memory usage of each application containing java in their launch-string, which should be most if not all java apps.

The output from my server is the following:

servername:~ servername$ ps aux | grep java
servername 50122   0.3  1.7  2832968  89236   ??  S    Thu08AM 117:55.94 /usr/bin/java -jar /srv/eurekaj/Proxy/eurekaJ.Proxy-1.0.RC1-jar-with-dependencies.jar
servername 72399   0.0 25.9  4978676 1355616   ??  S    29Jul11 1560:43.70 /usr/bin/java -Xmx2g -Xms1g -Djava.io.tmpdir=/tmp -Dbtrace.agent=HudsonAgent -javaagent:/srv/btrace/1.2/btrace-agent.jar=scriptdir=/srv/btrace/scripts,stdout=false,fileRollMilliseconds=7500 -jar hudson.war --httpPort=8093
servername 72392   0.0  8.3  3169604 437192   ??  S    29Jul11 120:41.42 /usr/bin/java -Xmx256m -Xms256m -Djava.io.tmpdir=/jettytmp -Dbtrace.agent=JSFlotDemoAgent -Dlog4j.configuration=file:/srv/jsflot/demo/log4j.xml -javaagent:/srv/btrace/1.2/btrace-agent.jar=scriptdir=/srv/btrace/scripts,stdout=false,fileRollMilliseconds=7500 -classpath :very_verbose_classpath org.jsflot.server.JettyServer
servername 97501   0.0  0.0  2425712    276 s000  R+    4:58AM   0:00.00 grep java

What you can read from this is PID, CPU Usage (%) and Memory Usage (%) for each of the processes.

You can also use the

top

command to get similar results.

Upvotes: 2

Related Questions