Hello,
I have some checks for btrfs usage that are failing. The problem lies in the / filesystem configuration which on those machines have 2 devices.
For example, the btrfs output for one is:
myhost $ btrfs filesystem sh --raw /
Label: none uuid: 0cd6d969-fddf-4eba-92fd-8826a9a73376
Total devices 2 FS bytes used 13946572800
devid 1 size 15025045504 used 11143217152 path /dev/sdu2
devid 2 size 11811160064 used 5939134464 path /dev/sdu3
The check uses this line for the calculation:
ocupatpercent=`sudo /usr/sbin/btrfs filesystem sh --raw $volum | awk '$1=="devid" {print int( 100-((($4-$6)/$4)*100) )}'`
which calculates de used percentage for each device so instead of one value:
myhost $ echo $ocupatpercent
74 50
My quick solution, replacing that one line in the script is this:
# saves total space of both devices ($4) in an array
total=( `sudo /usr/sbin/btrfs filesystem sh --raw $volum | awk '$1=="devid" {print $4}'` )
# saves used space of both devices ($6) in an array
usage=( `sudo /usr/sbin/btrfs filesystem sh --raw $volum | awk '$1=="devid" {print $6}'` )
# sums each device total space
total_space=$(( ${totala0]}+${totala1]} ))
# sums each device used space
total_usage=$(( ${usagea0]}+${usagea1]} ))
# calculates used percentage from the sum of both total and used space
ocupatpercent=$(( $total_usage*100/$total_space ))
So basically, I sum the total space and the total used space for both devices and use that to calculated the used percentage of /.
So my first question is, is this the correct way to calculate used space for this setup of btrfs?
And, how can I improve the calculation (making it simpler and clearer)?
Regards,
Enrique