Quick Tip: Profiling Java/Tomcat inside Docker with VisualVM
source link: https://sj14.gitlab.io/post/2019/07-31-java-profiling/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Introduction
The tutorials I’ve found [1] [2] are modifying the Dockerfile and create their own image, but this is not necessary, you can just pass the required environment variables to docker run
.
docker run -e JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost" -p 9090:9090/tcp -d some-java-image
Tomcat
Basically, it’s the same as for all other Java applications, but for Tomcat, you should use CATALINA_OPTS
instead of JAVA_OPTS
, which would still work (but a good argument against).
docker run -e CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost" -p 8080:8080/tcp -p 9090:9090/tcp -d tomcat
VisualVM
In the docker container, JMX is exposed to port 9090. To profile with VisualVM right click on Local -> Add JMX Connection -> Connection: localhost:9090
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK