diff --git a/custom-metrics/disk-usage.sh b/custom-metrics/disk-usage.sh index 79d35d8..560a78e 100644 --- a/custom-metrics/disk-usage.sh +++ b/custom-metrics/disk-usage.sh @@ -22,27 +22,28 @@ for i in {1..6}; do # Use process substitution instead of pipe to avoid subshell issues if [[ "$OS_TYPE" == "macos" ]]; then # macOS df format: Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on - # Mount points can have spaces, so we need to handle the full line - while IFS= read -r line; do - # Skip header line - if [[ "$line" =~ ^Filesystem ]]; then + # Skip pseudo-filesystems (map auto_home, map auto_nfs) and devfs + df 2>/dev/null | tail -n +2 | while IFS= read -r line; do + # Get the first field to check filesystem type + filesystem=$(echo "$line" | awk '{print $1}') + + # Skip map entries and other pseudo-filesystems + if [[ "$filesystem" == "map" || "$filesystem" == "devfs" ]]; then continue fi - # Extract fields using awk (handles multi-word mount points) - filesystem=$(echo "$line" | awk '{print $1}') + # For valid filesystems, extract: blocks (col 2), used (col 3), mount point (col 9+) blocks=$(echo "$line" | awk '{print $2}') used=$(echo "$line" | awk '{print $3}') - # Mount point is everything from column 9 onwards mount=$(echo "$line" | awk '{for(i=9;i<=NF;i++) printf "%s%s", $i, (i> "$LOGFILE" fi - done < <(df 2>/dev/null) + done else # Linux df with --output flag while read -r mount used total; do