I'm need to get a JVM heap dump from an Elastic Beanstalk server, but the server doesn't have jcmd or jmap. Amazon doesn't natively install them with the JDK. Here's what's installed:
[ec2-user@ip-x-x-x-x ~]$ sudo yum list installed|grep jdk
java-1.7.0-openjdk.x86_64 1:1.7.0.111-2.6.7.2.68.amzn1 @amzn-updates
java-1.8.0-openjdk.x86_64 1:1.8.0.101-3.b13.24.amzn1 @amzn-updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.101-3.b13.24.amzn1 @amzn-updates
What's the best way to get a heap dump from the JVM on Elastic Beanstalk?
I have found you can install jmap by installing the correct package:
sudo yum install java-1.8.0-openjdk-devel
This should at least allow a heap dump to be generated.
In addition, to make sure all functions in jmap run, also install:
sudo yum --enablerepo='*-debug*' install java-1.8.0-openjdk-debuginfo
Although this might depend on the baseline, tomcat version etc you use.
When creating a heap dump, use the tomcat user:
sudo -u tomcat jmap -dump:live,file=/tmp/test.hprof <pid>
Disclamer: I've never worked with Elastic Beanstalk, but I can recommend to check the following:
Consider taking the heap dump programmatically, I mean from within the Java application itself. There are many ways of doing that:
Via JMX - the chances are that you'll find HotSpotDiagnostic bean and will be able to invoke the heap dump operation (Here there is a tutorial for doing this)
If your application is new and you have Spring Boot, then probably its possible to plug Spring Actuator that has a "/heapdump" endpoint just for this purpose
来源:https://stackoverflow.com/questions/44650942/best-method-for-inspecting-elastic-beanstalk-jvm-heap