chore: JFR 24 hour script with logs file (#36041)
## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Sanity" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10807975642> > Commit: 660a59d4d52c8bf00e6126e2eb147465626a1989 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10807975642&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Wed, 11 Sep 2024 08:50:21 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Introduced a new automated script for recording Java Flight Recorder (JFR) data over a 24-hour period, enhancing monitoring capabilities for Java applications. - The script captures thread profiles at hourly intervals, streamlining performance data collection without manual intervention. - Added a monitoring setup function that conditionally executes the JFR recording script based on environment configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Goutham Pratapa <goutham@appsmith.com>
This commit is contained in:
parent
511268e29f
commit
1760132c28
54
deploy/docker/fs/opt/appsmith/JFR-recording-24-hours.sh
Normal file
54
deploy/docker/fs/opt/appsmith/JFR-recording-24-hours.sh
Normal file
|
|
@ -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
|
||||
|
|
@ -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 "$@"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user