Disk usage tweaks

This commit is contained in:
Alexandru-Victor Macocian
2025-10-30 17:54:54 +01:00
parent 4ac76bca4d
commit 87b0d2dbbf
2 changed files with 14 additions and 5 deletions
+12 -4
View File
@@ -22,14 +22,22 @@ 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
while read -r filesystem blocks used avail capacity iused ifree iusedpct mount; do
# Mount points can have spaces, so we need to handle the full line
while IFS= read -r line; do
# Skip header line
if [[ "$filesystem" == "Filesystem" ]]; then
if [[ "$line" =~ ^Filesystem ]]; then
continue
fi
# Convert 512-byte blocks to bytes
if [[ -n "$mount" && -n "$used" && -n "$blocks" ]]; then
# Extract fields using awk (handles multi-word mount points)
filesystem=$(echo "$line" | awk '{print $1}')
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<NF?" ":""); print ""}')
# Skip entries with 0 blocks (pseudo filesystems) or starting with dash
if [[ -n "$mount" && -n "$used" && -n "$blocks" && "$blocks" != "0" && ! "$filesystem" =~ ^- ]]; then
used_bytes=$((used * 512))
total_bytes=$((blocks * 512))
echo "$timestamp $mount $used_bytes $total_bytes" >> "$LOGFILE"
+2 -1
View File
@@ -43,6 +43,7 @@ fi
LogInformation "Starting power usage monitoring (OS: $OS_TYPE)"
# Run 6 iterations with 10-second intervals = 60 seconds total (no gaps)
for i in {1..6}; do
timestamp=$(GetTimestamp)
@@ -115,7 +116,7 @@ for i in {1..6}; do
fi
if [ $i -lt 6 ]; then
sleep 9
sleep 10
fi
done