Show Storage Disk Data Used %

Frank_Sonder
Contributor

Hello,

I'd like to show the Data Disk Used in percentage on an EA so that I can extract a report with all my computers and how much percentage of our users are using their disk drive. I just can't find it in EA templates and the boot percentage is not what I want. Thanks

Screenshot 2023-02-21 at 1.23.07 PM.png

2 ACCEPTED SOLUTIONS

sdagley
Esteemed Contributor II

@Frank_Sonder With APFS "sharing" free space across all partitions in a container the free space on the Boot partition should actually be the same as on the Data partition. Note the data Jamf Pro reports for Storage on one of my test Macs:

Storage on APFS.png

View solution in original post

mm2270
Legendary Contributor III

@sdagley's answer above is the correct answer. I was mistaken. Jamf shows the aggregated free space across all partitions in the container disk, so you should just create a report with "Boot Drive Available" as a column, and that should give you what you want, if that's indeed what you're after.

View solution in original post

12 REPLIES 12

mm2270
Legendary Contributor III

So.... you only want to know the percentage of space used in the Macintosh HD - Data volume?

Exactly, I wanna see how much they use on the HDD and what's left in space

sdagley
Esteemed Contributor II

@Frank_Sonder With APFS "sharing" free space across all partitions in a container the free space on the Boot partition should actually be the same as on the Data partition. Note the data Jamf Pro reports for Storage on one of my test Macs:

Storage on APFS.png

obi-k
Valued Contributor III

If you're trying to spit out a report, can you do this?

1. Computers

2. Search Inventory

3. New

4. Displays tab

5. Storage tab

6. Check off "Boot Drive Percentage Full"

7. Save

8. Download report

Yes

mm2270
Legendary Contributor III

But you're saying in your original post that the Boot Percentage Full is not what you want. Because, it doesn't show the same value as the Data volume percentage? I haven't really paid attention to that, but I can believe that since the boot volume is not the one users write their data too anymore. So you'll need a custom EA to capure that. Unless you can use an API call to grab this info that shows in the computer details. I haven't checked that out.

I did whip this together just now. I think it should show you what you want, but you'll have to test it out.

 

#!/bin/zsh

## Determine Data volume ID
data_volume_id=$(/usr/sbin/diskutil list internal | /usr/bin/awk '/APFS/ && /- Data/{print $NF}')

## Get total and free disk space amount in bytes
data_volume_total=$(/usr/sbin/diskutil info $data_volume_id | /usr/bin/awk -F'[(|B]' '/Total Space/{print $3}')
data_volume_free=$(/usr/sbin/diskutil info $data_volume_id | /usr/bin/awk -F'[(|B]' '/Free Space/{print $3}')

## Calculate % of used space using the above values
data_volume_used=$(/bin/echo "scale=3; 100 - $data_volume_free / $data_volume_total * 100" | /usr/bin/bc)

## Print back result, trimming to one value past the decimal point
/bin/echo "<result>$(printf "%.1f\n" ${data_volume_used})%</result>"

 

 

I think the boot percentage and data give me the wrong numbers... Sorry for the confusion... I think I just need to know what's available in space on the HDD (I'll do the percentage later on a sheet)
Screenshot 2023-02-21 at 2.24.48 PM.png

mm2270
Legendary Contributor III

Not sure I understand what you're after. You want the available space on the internal disk as a whole? Is that what you mean by the HDD? I'm not sure how easy that is to gather now with all the partitions the OS creates. 

mm2270
Legendary Contributor III

@sdagley's answer above is the correct answer. I was mistaken. Jamf shows the aggregated free space across all partitions in the container disk, so you should just create a report with "Boot Drive Available" as a column, and that should give you what you want, if that's indeed what you're after.

Oh my! It was just that! Thank you, guys! Greatly appreciate ! Thanks for the script which can be useful too!

mm2270
Legendary Contributor III

It's up to you, but I would give @sdagley the "answer" for this. I was just reiterating what he posted above.

Either way, glad that helped get you sorted out on this.

efil4xiN
Contributor II

if you still wan to go the EA route. this is what we use

#!/bin/sh
#https://www.jamf.com/jamf-nation/discussions/12546/boot-volume-free-space-ea


DU=$(df -h / | awk 'END{ print $(NF-4) }')


echo "<result>$DU</result>"

 

and this to drill down into user home folders

#!/bin/sh

LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'`
	

LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +1G`

echo "<result>$LARGEFILE</result>"

 

as always test, test ,test before deployng to PROD