Skip to content

Commit f973657

Browse files
authored
Update performance data with flag to clean up javacores (#782)
* Add flag to clean up javacores after they are packaged * Set linperf.sh script version
1 parent 913b9a4 commit f973657

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

internal/controller/assets/helper/linperf.sh

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
# --cpu-threshold=<value> triggers a data collection when the specified CPU threshold is reached.
2121
# --check-cpu-interval=<value> checks a process's CPU usage at interval in seconds. Default is 30.
2222
# --disable-irix-mode caps CPU usage at 100% in this script.
23-
# --disable-collecting-ifconfig to disable collecting ifconfig
24-
# --disable-collecting-hostname to disable collecting hostname
23+
# --disable-collecting-ifconfig disables collecting ifconfig
24+
# --disable-collecting-hostname disables collecting hostname
25+
# --clean-up-javacores removes javacores after archiving (includes any created during execution)
2526
#
2627
# Example with some options against a Java PID:
2728
# A javacore/thread dump every 5 seconds, running for 30 seconds:
@@ -50,8 +51,8 @@ CHECK_CPU_INTERVAL=30 # How often the script should check a process's CPU usag
5051
# It only works with -c <value> or --cpu-threshold=<value>.
5152
MONITOR_ONLY=0 # Monitoring trigering events only with no data created.
5253
# It only works with -c <value> or --cpu-threshold=<value>. Default=0
53-
KEEP_QUIET=0 # To disable the end print message, change to 1. Default=0
54-
ALLOW_STATS=0 # To collect OS data without provided PIDs, change to 1. Default=0
54+
KEEP_QUIET=0 # Disable the end print message, change to 1. Default=0
55+
ALLOW_STATS=0 # Collect OS data without provided PIDs, change to 1. Default=0
5556
ROOT_ACCESS_REQUIRED=1 # Default=1 to require root for running the script.
5657
DISABLE_COLLECTING_IFCONFIG=0 # Default=0 to collect ifconfig info
5758
DISABLE_COLLECTING_HOSTNAME=0 # Default=0 to collect hostname info
@@ -62,7 +63,7 @@ DISABLE_COLLECTING_HOSTNAME=0 # Default=0 to collect hostname info
6263
# that may not be useful towards resolving the issue. This becomes a problem
6364
# when the process of collecting data obscures the real issue.
6465
###############################################################################
65-
SCRIPT_VERSION=2025.04.14
66+
SCRIPT_VERSION=2025.09.19
6667
START_DAY="$(date +%Y%m%d)"
6768
START_TIME="$(date +%H%M%S)"
6869

@@ -109,11 +110,16 @@ while [ $# -gt 0 ]; do
109110
# Disable root requirement
110111
--ignore-root ) ROOT_ACCESS_REQUIRED=0; shift 1;;
111112

113+
# Clean up javacores after tarring.
114+
--clean-up-javacores ) CLEAN_UP_JAVACORES=1; shift 1;;
115+
112116
[0-9]* ) provided_pids="$provided_pids $1"; shift 1;;
113117

114118
* ) echo "Unknown option: $1"; exit 1;;
115119
esac
116120
done
121+
# echo "$monitor_log_file $match_trace $provided_pids"
122+
# exit 1
117123
#############################################
118124
# If PIDs are not provided, the script exits.
119125
#############################################
@@ -223,9 +229,9 @@ log()
223229
if [ -z "${DISABLE_SCREEN_OUTPUT}" ] && [ -n "$1" ] && [ $MONITOR_ONLY -ne 1 ] && [ -z "${HIDE_STAMP}" ]; then
224230
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" | tee -a screen.out
225231
elif [ -n "${DISABLE_SCREEN_OUTPUT}" ] && [ -n "${HIDE_STAMP}" ] && [ -n "$1" ]; then
226-
echo "$1"
232+
printf "%s\n" "$1"
227233
elif [ -n "${HIDE_STAMP}" ] && [ -n "$1" ]; then
228-
echo "$1" | tee -a screen.out
234+
printf "%s\n" "$1" | tee -a screen.out
229235
elif [ -n "$1" ]; then
230236
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
231237
fi
@@ -526,7 +532,13 @@ log "Final netstat snapshot complete."
526532
# Other data collection #
527533
#########################
528534
log "Collecting other data."
529-
dmesg > dmesg.out 2>&1
535+
dmesg="dmesg.out"
536+
if ! dmesg > /dev/null 2>&1; then
537+
dmesg=""
538+
log "dmesg data unavailable due to access restrictions (normal in containers/non-root)."
539+
else
540+
dmesg > dmesg.out 2>&1
541+
fi
530542
df -hk > df-hk.out 2>&1
531543

532544
# Terminate TOP processes created by this script.
@@ -542,18 +554,36 @@ trap 'kill $top_pids 2>/dev/null' EXIT
542554
log "Preparing for packaging and cleanup..."
543555
sleep 5
544556

557+
CleanUpJavacores()
558+
{
559+
# $1 - directory path
560+
# $2 - javacore files
561+
if [ -n "$CLEAN_UP_JAVACORES" ]; then
562+
log "Cleaning up the javacores in $1"
563+
for file in $2; do
564+
local full_path="$1/$file"
565+
if [ -f "$full_path" ]; then
566+
rm "$full_path" && log "Removed: $full_path " || log "Failed to remove: $full_path"
567+
else
568+
log "File not found to remove: $full_path"
569+
fi
570+
done
571+
fi
572+
}
573+
545574
# Tar javacores
546575
tarred_javacores_string=""
547576
pids_not_found_javacores="$no_longer_running_pids"
548577
TarJavacores()
549578
{
550-
#scriptdir=$(pwd)
551-
# $1 - directory
552-
# $2 - javacore filenames
579+
# $1 - directory path
580+
# $2 - javacore files
553581
# $3 - PID
554582
(cd ''"$1"'' && tar -cf ''"$OUTPUT_DIR/javacore.$3.tar"'' $2)
555-
temp_javacores_string="$tarred_javacores_string javacore.$3.tar "
583+
local temp_javacores_string="$tarred_javacores_string javacore.$3.tar "
556584
tarred_javacores_string=$temp_javacores_string
585+
# Remove the javacores if --clean-up-javacores is used.
586+
CleanUpJavacores "$1" "$2"
557587
}
558588
if [ -z "$disable_kill" ]; then
559589
for pid in $pids
@@ -588,7 +618,7 @@ screen_out="screen.out"
588618
if [ -n "${DISABLE_SCREEN_OUTPUT}" ]; then
589619
screen_out=""
590620
fi
591-
files_string="netstat.out vmstat.out ps.aux.out ps.out ps.threads.out top.out $screen_out dmesg.out whoami.out df-hk.out uptime.out $tarred_javacores_string $ifconfig_file"
621+
files_string="netstat.out vmstat.out ps.aux.out ps.out ps.threads.out top.out $screen_out $dmesg whoami.out df-hk.out uptime.out $tarred_javacores_string $ifconfig_file"
592622
for pid in $pids
593623
do
594624
temp_string="topdashH.$pid.out"
@@ -603,7 +633,7 @@ log "$(echo $files_string | sed 's/ / /g' | sed 's/ *$//')"
603633

604634
tar -cf ../$DIR_NAME.tar $files_string
605635
if [ $? -ne 0 ]; then
606-
echo $(date '+%Y-%m-%d %H:%M:%S') "\tDue to above tar issue, the mentioned files in $DIR_NAME are not removed."
636+
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "Due to above tar issue, the mentioned files in $DIR_NAME are not removed."
607637
dir_end_message="$OUTPUT_DIR"
608638
else
609639
gzip ../$DIR_NAME.tar
@@ -613,16 +643,15 @@ fi
613643
# Check if the current directory is empty before removing it.
614644
# Otherwise, print out message and the output dir will not be removed.
615645
if [ -n "$(ls -A)" ]; then
616-
echo $(date '+%Y-%m-%d %H:%M:%S') "\tFailed to remove the temporary $DIR_NAME directory."
646+
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "Failed to remove the temporary $DIR_NAME directory."
617647
else
618648
cd ..
619649
rm -r $DIR_NAME
620-
echo $(date '+%Y-%m-%d %H:%M:%S') "\tTemporary directory $DIR_NAME removed."
650+
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "Temporary directory $DIR_NAME removed."
621651
dir_end_message="$OUTPUT_DIR.tar.gz"
622652
fi
623653

624-
echo $(date '+%Y-%m-%d %H:%M:%S') "\tlinperf script complete."
625-
654+
printf "%s\t%s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "linperf script complete."
626655
if [ $KEEP_QUIET -eq 0 ]; then
627656
# Define colors and width
628657
YELLOW_BG="$(tput setaf 0)$(tput setab 3)"

utils/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func GetLinperfCmd(encodedAttrs, podName, podNamespace string) string {
232232
linperfCmdArgs = append(linperfCmdArgs, parseFlag("-j", decodedLinperfAttrs["interval"], FlagDelimiterSpace))
233233

234234
linperfCmdArgs = append(linperfCmdArgs, "--ignore-root")
235+
linperfCmdArgs = append(linperfCmdArgs, "--clean-up-javacores")
235236
linperfCmd := strings.Join(linperfCmdArgs, FlagDelimiterSpace)
236237

237238
requiredCLIs := []string{"netstat", "ps", "dmesg", "tput", "ifconfig", "vmstat", "top", "uptime", "hostname"}

0 commit comments

Comments
 (0)