diff --git a/proxDoc.sh b/proxDoc.sh index c7939ac..2f4af97 100755 --- a/proxDoc.sh +++ b/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