Cache disk list to avoid multiple lsblk calls
Add get_disk_list() function that caches the output of lsblk on first call. Subsequent calls return the cached value, reducing overhead when multiple functions need to iterate over disk devices. #8 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
18
proxDoc.sh
18
proxDoc.sh
@@ -13,6 +13,12 @@ readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands
|
||||
# Optional log file - set via environment variable PROXDOC_LOGFILE
|
||||
LOGFILE="${PROXDOC_LOGFILE:-}"
|
||||
|
||||
###################
|
||||
# Cached Data
|
||||
###################
|
||||
# Disk list cache - populated on first use
|
||||
DISK_LIST=""
|
||||
|
||||
###################
|
||||
# Pattern Constants
|
||||
###################
|
||||
@@ -114,6 +120,14 @@ checkIfOnHypervisor() {
|
||||
command -v pveversion >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Get disk list with caching to avoid multiple lsblk calls
|
||||
get_disk_list() {
|
||||
if [[ -z "$DISK_LIST" ]]; then
|
||||
DISK_LIST=$(lsblk -d -o name 2>/dev/null | grep -E "$DISK_DEVICE_PATTERN")
|
||||
fi
|
||||
echo "$DISK_LIST"
|
||||
}
|
||||
|
||||
###################
|
||||
# System Information Functions
|
||||
###################
|
||||
@@ -155,7 +169,7 @@ get_disk_health() {
|
||||
if ! timeout $CMD_TIMEOUT smartctl -H "/dev/$disk"; then
|
||||
log_message warn "smartctl timed out or failed for /dev/$disk"
|
||||
fi
|
||||
done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN")
|
||||
done <<< "$(get_disk_list)"
|
||||
else
|
||||
log_message warn "smartctl not found. Install smartmontools for disk health monitoring"
|
||||
fi
|
||||
@@ -588,7 +602,7 @@ quick_health_check() {
|
||||
else
|
||||
echo -e "/dev/$disk: ${YELLOW}check timed out or unavailable${NC}"
|
||||
fi
|
||||
done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN")
|
||||
done <<< "$(get_disk_list)"
|
||||
fi
|
||||
|
||||
# Node Exporter
|
||||
|
||||
Reference in New Issue
Block a user