SERVER-108254: Only execute du on filesystems that are getting full t… (#39215)

GitOrigin-RevId: 76b6940ec0849d442695a85d965e2cdc2e606f95
This commit is contained in:
Eric Lavigne 2025-07-28 13:27:46 -06:00 committed by MongoDB Bot
parent 4d7c9c7f2d
commit 6a2770b559
1 changed files with 12 additions and 6 deletions

View File

@ -1,24 +1,30 @@
# What percent a filesystem has to be filled to be considered "full" # What percent a filesystem has to be filled to be considered "full"
FULL_DISK_THRESHOLD=90 FULL_DISK_THRESHOLD=90
HAS_FULL_DISK=false HAS_FULL_DISK=false
declare -a FULL_DISKS
# This will output the percent each filesystem is full in the following format: # This will output the percent each filesystem is full in the following format:
# 91% /dev/root # 91% /dev/root /
# 7% /dev/nvme0n1p15 # 7% /dev/nvme0n1p15 /System/Volumes/Data
# 34% /dev/nvme1n1 # 34% /dev/nvme1n1 /System/Volumes/Update
FILESYSTEMS=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }') FILESYSTEMS=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom|map' | awk '{ print $5 " " $1 " " $9 }')
while read -r output; do while read -r output; do
usep=$(echo "$output" | awk '{ print $1}' | cut -d'%' -f1) usep=$(echo "$output" | awk '{ print $1}' | cut -d'%' -f1)
partition=$(echo "$output" | awk '{ print $2 }') partition=$(echo "$output" | awk '{ print $2 }')
mountpoint=$(echo "$output" | awk '{ print $3 }')
if [ $usep -ge $FULL_DISK_THRESHOLD ]; then if [ $usep -ge $FULL_DISK_THRESHOLD ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
HAS_FULL_DISK=true HAS_FULL_DISK=true
FULL_DISKS+=("$mountpoint")
fi fi
done <<<"$FILESYSTEMS" done <<<"$FILESYSTEMS"
if $HAS_FULL_DISK; then if $HAS_FULL_DISK; then
echo "Checking disks"
for item in "${FULL_DISKS[@]}"; do
# print all files that are above one megabyte sorted # print all files that are above one megabyte sorted
du -cha / 2>/dev/null | grep -E "^[0-9]+(\.[0-9]+)?[G|M|T]" | sort -h du -cha "$item" 2>/dev/null | grep -E "^[0-9]+(\.[0-9]+)?[G|M|T]" | sort -h
done
else else
echo "No full partitions found, skipping" echo "No full partitions found, skipping"
fi fi