I want to add a timestamp after the heap dump filename. It works when I specify the -XX:HeapDumpPath
option when running the command below:
java -Xmx64m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=outputFilename.$(date +_%m%d%Y.%H:%M:%S).bin -jar app.jar
But when this option is set on the Kubernetes service yml file is not working. Below is option defined in the yml file:
env:
- name: JAVA_TOOL_OPTIONS
value: " -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"/dumps/heap-dump/demo-heap-dump$(date +_%m%d%Y.%H:%M:%S).bin\""
It throws the error below when trying to create heap dump
2022-08-09 13:02:15.901 CESTPicked up JAVA_TOOL_OPTIONS: -Xmx1m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="/dumps/heap-dump/"demo-heap-dump$(date +_%m%d%Y.%H:%M:%S).bin
2022-08-09 13:00:56.853 CESTUnrecognized option: +_%m%d%Y.%H:%M:%S).bin
Thank you for your help.
Best regards, Rando.
I found a workaround to solve this issue. It is not possible to solve it by adding XX:HeapDumpPath=\"/dumps/heap-dump/demo-heap-dump$(date +_%m%d%Y.%H:%M:%S).bin\""
in yml because it will not be executed. For this line $(date +_%m%d%Y.%H:%M:%S)
to be executed it needs to run on the bash terminal.
I removed the line below from the yml file:
- name: JAVA_TOOL_OPTIONS
value: " -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"/dumps/heap-dump/demo-heap-dump$(date +_%m%d%Y.%H:%M:%S).bin\""
Modified the docker file to use bash to execute jar and not the java command like below:
FROM repo/jdk8
ADD target/app.jar app.jar
#CMD [ "java", "-jar", "/app.jar" ]
CMD ["/bin/bash", "-c", "java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps/heap-dump/app-heap-dump$(date +-%Y-%m-%d-%H-%M-%S).hprof -jar /app.jar "]
EXPOSE 5147
After the modification, I am to store the heap dump with the timestamps attached to the filename of the heap dump.