How to enable Garbage Collection (GC) logging in JBoss EAP domain mode
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
Issue
- How do I enable garbage collection logs for Domain/Host controllers?
- How do I enable garbage collection logs for individual servers running in Domain mode?
- CLI command to enable garbage collection logging?
Resolution
For Host/Domain Controller processes
In order to generate GC Logging for Host/Domain Controller, edit the "$JBOSS_HOME/bin/domain.conf" by adding the "HOST_CONTROLLER_JAVA_OPTS" with the following arguments:
HOST_CONTROLLER_JAVA_OPTS="-Xloggc:/home/user/jboss_home/domain/log/ControllerGC.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps $HOST_CONTROLLER_JAVA_OPTS"
Recommended: Use following CLI command to enable garbage collection logging:
/host=<host_name>/jvm=default:write-attribute(name=jvm-options,value=["-server","-verbose:gc ","-Xloggc:gc.log"])
For EAP server processes
Recommended: Use following CLI command to enable garbage collection logging:
JDK 8
/host=<host_name>/server-config=<server_name>/jvm=default:add()
### JDK 8::
/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/Server1GC.log","-XX:+PrintGCDetails","-XX:+PrintGCDateStamps","-XX:+PrintGCApplicationStoppedTime"])
Above command will result in the following XML block in host.xml (or host-slave.xml, in case --host-config=host-slave.xml is used):
<servers>
<server name="Server1" group="other-server-group" auto-start="true">
<jvm name="default">
<jvm-options>
<option value="-verbose:gc"/>
<option value="-Xloggc:${jboss.domain.servers.dir}/server-one/log/Server1GC.log"/>
<option value="-XX:+PrintGCDetails"/>
<option value="-XX:+PrintGCDateStamps"/>
<option value="-XX:+PrintGCApplicationStoppedTime"/>
</jvm-options>
</jvm>
<socket-bindings socket-binding-group="full-ha-sockets" port-offset="100"/>
</server>
</servers>
The file name of the GC log, specified by -Xloggc: option, is fixed the server is restarted, the previous property is overwritten. Make sure to take a backup of the logs before starting the server.
JDK 11
For JDK 11, the option above is invalid, do this instead:
/host=<host_name>/server-config=<server_name>/jvm=default:add()
### JDK 11:
/host=<host_name>/server-config=<server_name>/jvm=default:write-attribute(name=jvm-options,value=["-Xlog:gc*:file=${jboss.domain.servers.dir}/server-one/log/gc.log.%t:tags,time,uptime,level:filecount=5,filesize=20M"])
This will result a host.xml or host-slave.xml changed for:
<jvm name="default">
<jvm-options>
<option value="-Xlog:gc*:file=${jboss.domain.servers.dir}/server-one/log/gc.log.%t:tags,time,uptime,level:filecount=5,filesize=20M"/>
</jvm-options>
Regarding JDK 11, see more details on JDK 11 Logging mechanism with -Xlog Option.
Once a file is generated, check How do I analyze Java garbage collection logging? to gather further details.
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.