Skip to content

Instantly share code, notes, and snippets.

@aspyker
Last active April 27, 2021 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aspyker/2a9ecaed1a2c79f1b0d6 to your computer and use it in GitHub Desktop.
Save aspyker/2a9ecaed1a2c79f1b0d6 to your computer and use it in GitHub Desktop.
running jmxterm from command line to force gc
wget http://downloads.sourceforge.net/project/cyclops-group/jmxterm/0.2/jmxterm-0.2-uber.jar
a@a:~$ java -jar jmxterm-0.2-uber.jar
Welcome to JMX terminal. Type "help" for available commands.
?$ open localhost:8076
Connection to localhost:8076 is opened
>$ bean java.lang:type=Memory
bean is set to java.lang:type=Memory
>$ run gc
calling operation gc of mbean java.lang:type=Memory
operation returns:
null
jmap -dump:format=b,file=memory.hprof PIDHERE
sometimes
sudo jmap -dump:format=b,file=memory.hprof PIDHERE
sometimes
sudo -u useridofprocess jmap -dump:format=b,file=memory.hprof PIDHERE
sometimes requires
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
make sure CWD or process is writeable by owner of process
jstat -gcnew -h 10 PIDHERE 2000
jstat -gcold -h 10 PIDHERE 2000
@sarnobat
Copy link

sarnobat commented Apr 27, 2021

Ugh. I just tried jmxterm and it's not very convenient the way you have to interactively type it all or use an expect script. https://gist.github.com/maurorappa/07ce39130cbb1249f8f3746393d66a02#file-monitoring-via-jmx-for-long-periods
My jar is easier to use: https://github.com/sarnobat/jmx_programmatic/blob/main/src/main/java/PrintMBeans.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment