Skip to content

Conversation

@Cryptominer937
Copy link
Contributor

@Cryptominer937 Cryptominer937 commented Jun 13, 2025

re-wrote ZFSCHECK to handle large disks more cleanly and to prevent errors like

bash: line 570: ((: 7.3T
17: syntax error: invalid arithmetic operator (error token is ".3T
17")

I originally used bc but changed it to awk cause not all systems will have bc.

Also added -t zfs so it will display disk size in the summary for zfs disks.

Commented as best I can

Tested on Debian 12, Ubuntu 22.04 / 24.04, and Proxmox VE 8.4.1

Fixed
syntax error: invalid arithmetic operator (error token is ".3T
17" Line 570 so rewrote the ZFSCHECK

Caused by having 7.3T Free Space
Actual output "hddpool                   zfs       7.8T  514G  7.3T   7% /hddpool"

Line 270 Added ZFS as a option so we can display Disk Space.

Tested on Debian 12, Ubuntu 24.04, and Proxmox 8.4.1
switch to awk from bc
@masonr
Copy link
Owner

masonr commented Jun 13, 2025

Thanks for the updates to the ZFS fio section. I do have some concerns on adding -t zfs for the disk size calculations. I've made several attempts to get that added, but ran into the issue where ZFS volumes were being added multiple times due to how the filesystem is handled (ref #35 and #69). Until we can figure out how to resolve that, I'm reluctant to adjust the df disk summation line.

@Cryptominer937
Copy link
Contributor Author

I reverted the line 270 modification for disk summary, so this is now just the changes for the ZFSCHECK.

I use the tool quite a bit and figured since I saw a error why not find a solution and submit it your way.

@Cryptominer937
Copy link
Contributor Author

Cryptominer937 commented Jun 13, 2025

as to the zfs raw disk issue maybe something like this I only tested on my Proxmox VE 8.4.1Host.

# total disk size is calculated by adding all partitions of the types listed below (after the -t flags)
TOTAL_DISK_RAW=$(df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t exfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $2 }')

# If df returns empty, set TOTAL_DISK_RAW to 0
if [ -z "$TOTAL_DISK_RAW" ]; then
  TOTAL_DISK_RAW=0
fi
ZFS_POOL_SIZE=0

if command -v zpool &>/dev/null; then
    ZFS_POOL_SIZE=$(zpool list -p -H 2>/dev/null | awk '{sum+=$2} END {print sum}')
    
fi

TOTAL_DISK_SUM_BYTES=$(awk -v total_raw="$TOTAL_DISK_RAW" -v zfs_size="$ZFS_POOL_SIZE" 'BEGIN {print total_raw + zfs_size}')
format_size() {
    local bytes="$1"
    # Check if bytes is empty or non-numeric
    if [[ -z "$bytes" || ! "$bytes" =~ ^[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+)?$ ]]; then
        echo "0B"
        return
    fi
#Use awk for robust floating-point calculation and formatting
    # This awk script will convert bytes to the most appropriate unit.
    awk -v b="$bytes" '
    BEGIN {
        if (b < 1024) {
            printf "%.0fB\n", b
        } else if (b < 1024^2) {
            printf "%.2fKB\n", b / 1024
        } else if (b < 1024^3) {
            printf "%.2fMB\n", b / (1024^2)
        } else if (b < 1024^4) {
            printf "%.2fGB\n", b / (1024^3)
        } else if (b < 1024^5) {
            printf "%.2fTB\n", b / (1024^4)
        } else { # For even larger units (PB)
            printf "%.2fPB\n", b / (1024^5)
        }
    }'
}

TOTAL_DISK=$(format_size "$TOTAL_DISK_SUM_BYTES")

@Cryptominer937
Copy link
Contributor Author

Tested the above for disk size RAW on Many systems with zfs including Proxmox, Virtualizor, and A custom Containerized setup using raw zvols and it just gets the raw size of the root zfs array ignoring all sub zvols, So far has tested very reliably in getting the Raw Disk size for ZFS. Again this is only for getting the Raw size for Basic System info summary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants