How to rotate gc log file configured in domain mode in EAP 6 and 7?

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x
  • Java

Issue

  • How to rotate gc log file configured in domain mode in EAP 6 and EAP 7 ?

Resolution

  • To rotate the gc.log file based on size , need to add "-XX:+UseGCLogFileRotation" , "-XX:NumberOfGCLogFiles" , "-XX:GCLogFileSize" in the JVM_OPTIONS . Details of theses options is as follows :
-XX:+UseGCLogFileRotation : Enabled GC log rotation, requires -Xloggc.

-XX:NumberOfGCLogFiles : Set the number of files to use when rotating logs, must be >= 1. The rotated log files will use the following naming scheme, <filename>.0, <filename>.1, ..., <filename>.n-1.

-XX:GCLogFileSize : The size of the log file at which point the log will be rotated, must be >= 8K. You can specify -XXGCLogFileSize=100K or -XXGCLogFileSize=1M format. The smallest value of -XX:GCLogFileSize you can specify is 8K.
  • The configuration in the host.xml file will be as follows :
  <servers>
    <server name="server-one" group="main-server-group">
      <jvm name="default">
        <heap size="4096m" max-size="4096m"/>
        <permgen size="512m" max-size="1024m"/>
        <jvm-options>
          <option value="-verbose:gc"/>
          <option value="-Xloggc:${jboss.domain.servers.dir}/server-one/log/server-one-gc_%p_%t.log"/>
          <option value="-XX:+PrintGCDetails"/>
          <option value="-XX:+PrintGCTimeStamps"/>
          <option value="-XX:+PrintGCDateStamps"/>
          <option value="-XX:+PrintGCApplicationStoppedTime"/>
          <option value="-XX:+UseGCLogFileRotation"/>
          <option value="-XX:GCLogFileSize=3M"/>
          <option value="-XX:NumberOfGCLogFiles=5"/>
        </jvm-options>
      </jvm>
    </server>
    ...(snip)...
  </servers>

the following JBoss-CLI command can add the above to configuration file:

/host=<host_name>/server-config=<server_name>/jvm=default:write-attribute(name=jvm-options,value=["-verbose:gc", "-Xloggc:${jboss.domain.servers.dir}/server-one/log/server-one-gc_%p_%t.log", "-XX:+PrintGCDetails", "-XX:+PrintGCTimeStamps", "-XX:+PrintGCDateStamps", "-XX:+PrintGCApplicationStoppedTime", "-XX:+UseGCLogFileRotation", "-XX:GCLogFileSize=3M", "-XX:NumberOfGCLogFiles=5"])

you also need to restart the server instance to reflect the JVM option changes:

/host=<host_name>/server-config=<server_name>:restart
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.