diff --git a/deploy/docker/fs/opt/appsmith/JFR-recording-24-hours.sh b/deploy/docker/fs/opt/appsmith/JFR-recording-24-hours.sh new file mode 100644 index 0000000000..ea26f0247a --- /dev/null +++ b/deploy/docker/fs/opt/appsmith/JFR-recording-24-hours.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset +set -o noglob + +# Define the log file path +log_dir=$1 +log_file=$log_dir/loop.log + +# Ensure the log directory exists +mkdir -p $log_dir + +# Start logging +echo "Script started at $(date)" > $log_file + +echo "Sleep 180 seconds to wait for backend to be ready at $(date)" >> $log_file +sleep 180 + +# Run the loop for 24 hours (or 24 attempts) +for i in {1..24}; do + echo "Attempt $i at $(date)" >> $log_file + + location=$log_dir/heap_dumps/ad-hoc-24-hours/${HOSTNAME}/thread-profile/profile-$(date "+%Y_%m_%d_%H_%M_%S") + mkdir -p $location + echo "Created directory $location" >> $log_file + + # Get the PID of the Java process + pid=$(pgrep -f -- "-jar\sserver.jar") + echo "Found java process at $pid...." >> $log_file + if [ -z "$pid" ]; then + echo "Java process not found, skipping this attempt." >> $log_file + continue + fi + + echo "Found Java PID: $pid" >> $log_file + + # Stop any ongoing JFR recording + jcmd $pid JFR.stop name=profile || true + echo "Stopped previous JFR recording (if any)" >> $log_file + + # Start a new JFR recording + jcmd $pid JFR.start name=profile filename=$location.jfr + echo "Started new JFR recording: $location.jfr" >> $log_file + + # Wait for an hour before taking the next thread dump + echo "Sleeping for 1 hour..." >> $log_file + sleep 3600 + jcmd $pid JFR.stop name=profile || true +done >> $log_file 2>&1 & + +# Detach the process from the terminal +echo "Script disowned, running in background." >> $log_file \ No newline at end of file diff --git a/deploy/docker/fs/opt/appsmith/entrypoint.sh b/deploy/docker/fs/opt/appsmith/entrypoint.sh index 17eaf3a72d..1d5bd59fde 100644 --- a/deploy/docker/fs/opt/appsmith/entrypoint.sh +++ b/deploy/docker/fs/opt/appsmith/entrypoint.sh @@ -477,6 +477,14 @@ function setup_auto_heal(){ fi } +function setup_monitoring(){ + if [[ ${APPSMITH_MONITORING-} = 1 ]]; then + # By default APPSMITH_MONITORING=0 + # To enable auto heal set APPSMITH_MONITORING=1 + bash /opt/appsmith/JFR-recording-24-hours.sh $APPSMITH_LOG_DIR 2>&1 & + fi +} + print_appsmith_info(){ tr '\n' ' ' < /opt/appsmith/info.json } @@ -530,6 +538,7 @@ mkdir -p "$APPSMITH_LOG_DIR"/{supervisor,backend,cron,editor,rts,mongodb,redis,p setup_auto_heal capture_infra_details +setup_monitoring || echo true # Handle CMD command exec "$@"