Skip to content

Commit fb72699

Browse files
committed
fix: improve storage metrics calculation in entrypoint.sh
1 parent 01e3183 commit fb72699

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Yolk/entrypoint.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,18 +523,20 @@ _metrics_read_memory() {
523523
}
524524

525525
# Returns "<used_bytes> <total_bytes>" for the container home directory.
526-
# Uses -B1 (POSIX/busybox-compatible) rather than --block-size=1 (GNU-only).
526+
# used = actual bytes consumed by files inside /home/container (via du).
527+
# total = total capacity of the underlying filesystem (via df -B1).
527528
_metrics_read_storage() {
529+
local used=0 total=0 df_line
530+
if command -v du &>/dev/null; then
531+
used="$(du -sb "${CONTAINER_HOME}" 2>/dev/null | awk '{print $1}')" || used=0
532+
fi
528533
if command -v df &>/dev/null; then
529-
local used=0 total=0 df_line
530534
df_line="$(df -B1 "${CONTAINER_HOME}" 2>/dev/null | tail -1)" || df_line=""
531535
if [ -n "$df_line" ]; then
532-
read -r _ total used _ _ _ <<< "$df_line" || true
536+
read -r _ total _ _ _ _ <<< "$df_line" || true
533537
fi
534-
echo "${used:-0} ${total:-0}"
535-
else
536-
echo "0 0"
537538
fi
539+
echo "${used:-0} ${total:-0}"
538540
}
539541

540542
# Returns "<rx_bytes> <tx_bytes>" cumulative for all non-loopback interfaces.

0 commit comments

Comments
 (0)