Search code examples
javaamazon-ec2jvmamazon-elastic-beanstalkheap-dump

Best method for inspecting Elastic Beanstalk JVM heap


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?


Solution

  • 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>