Enabling garbage collection logging with Tomcat on a Linux/UNIX platform
search cancel

Enabling garbage collection logging with Tomcat on a Linux/UNIX platform

book

Article ID: 331379

calendar_today

Updated On:

Products

VMware Support Only for Apache Tomcat

Issue/Introduction

This article provides information on how to enable garbage collection logging with Apache Tomcat, vFabric ERS Tomcat, or vFabric tc Server Runtime on a Linux or UNIX platform. In all these cases, you need to add options to the Java executable, but the method is different for each product. The same method can be used for specifying other options for Java.

Environment

VMware vFabric Enterprise Ready Server 4
Apache Tomcat 5.5
Apache Tomcat 6
Apache Tomcat 7
VMware vFabric tc Server 2.1
VMware vFabric tc Server 2.0
VMware vFabric tc Server 2.6
VMware vFabric tc Server 2.5

Resolution

For each product, the example in this article assumes that the GC log should go (as specified using -Xloggc) to the same standard location as other logs. Several recommended parameters are given in the examples. You may need to adjust the examples according to your requirement.

Apache Tomcat

To enable garbage collection logging with Apache Tomcat:
  1. Create a setenv.sh file in the $TOMCAT_HOME/bin directory.
  2. Add these entries to the file:

    export CATALINA_OPTS=" \

    -XX:+PrintGCTimeStamps \
    -XX:+PrintGCDetails \
    -XX:+PrintGCApplicationStoppedTime \
    -XX:+PrintGCApplicationConcurrentTime \
    -XX:+PrintHeapAtGC \
    -Xloggc:logs/gc.log"

    Note: If the setenv.sh already exists, you need to merge these entries to the existing options.

    This script is executed when Apache Tomcat is started and sets the JVM options needed to enable garbage collection logging.

  3. Restart Apache Tomcat to enable the changes.

vFabric ERS Tomcat

To enable garbage collection logging on ERS Tomcat:
  1. Open the bin/tomcat_startup.sh script using a text editor.
  2. Locate the line in the script that specifies jvm_options. For example:

    jvm_options="-server -Xmx256m"

  3. Modify this line by adding the new GC parameters to the end of the existing ones, ensuring that everything is in a single line:

    jvm_options="-server -Xmx256m -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -Xloggc:logs/gc.log"

  4. Restart the ERS Tomcat instance for the changes to take effect.

vFabric tc Server Runtime

To enable garbage collection logging under tc Server:
  1. Open the bin/setenv.sh script file for an instance of the runtime using a text editor.
  2. Locate the SUN_JVM_OPTS variable. By default, this variable is commented.
  3. To enable garbage collection logging, un-comment the variable and modify it as:

    SUN_JVM_OPTS="-XX:+PrintGCTimeStamps \
    -XX:+PrintGCDetails \
    -XX:+PrintGCApplicationStoppedTime \
    -XX:+PrintGCApplicationConcurrentTime \
    -XX:+PrintHeapAtGC \
    -Xloggc:logs/gc.log"

  4. Restart the runtime instance for the changes to take effect.