Collect partition info and unify storage table with disk, partition, and usage data
All checks were successful
Build-Publish / build (linux/arm64) (push) Successful in 13s
Build-Publish / build (linux/amd64) (push) Successful in 3s
Build-Publish / create-manifest (push) Successful in 8s
Build-Publish / publish-template (push) Successful in 15s

This commit is contained in:
j
2026-03-10 21:57:46 +13:00
parent 9d288b7430
commit a384352954
2 changed files with 78 additions and 24 deletions

View File

@@ -103,19 +103,29 @@ if [ -n "$total_kb" ] && [ -n "$available_kb" ]; then
echo "available_mb=$available_mb"
fi
# Physical disks
lsblk -b -n -o NAME,SIZE,TYPE 2>/dev/null | while read -r name size type; do
if [ "$type" = "disk" ]; then
echo "[disk:$name]"
echo "name=$name"
echo "size_bytes=$size"
# Physical disks and partitions
lsblk -b -n -P -o NAME,SIZE,TYPE,MOUNTPOINT,PKNAME 2>/dev/null | while read -r line; do
eval "$line"
if [ "$TYPE" = "disk" ]; then
echo "[disk:$NAME]"
echo "name=$NAME"
echo "size_bytes=$SIZE"
elif [ "$TYPE" = "part" ]; then
echo "[partition:$NAME]"
echo "name=$NAME"
echo "size_bytes=$SIZE"
echo "parent=$PKNAME"
echo "mount=$MOUNTPOINT"
fi
done
# Mounted filesystem usage
df -B1 --output=target,size,used,avail,pcent 2>/dev/null | tail -n +2 | while read -r mount total used avail percent; do
# Mounted filesystem usage (exclude virtual filesystems)
df -B1 --output=target,size,used,avail,pcent \
-x tmpfs -x devtmpfs -x squashfs -x overlay -x efivarfs -x nsfs \
2>/dev/null | tail -n +2 | while read -r mount total used avail percent; do
case "$mount" in
/|/home|/var|/tmp|/boot|/data*|/mnt*|/srv*|/opt*)
/dev|/dev/*|/proc|/proc/*|/sys|/sys/*|/run|/run/*|/snap/*) continue ;;
esac
safename=$(echo "$mount" | tr '/' '_')
echo "[disk_usage:${safename}]"
echo "mount=$mount"
@@ -123,8 +133,6 @@ df -B1 --output=target,size,used,avail,pcent 2>/dev/null | tail -n +2 | while re
echo "used_bytes=$used"
echo "available_bytes=$avail"
echo "usage_percent=${percent%\%}"
;;
esac
done
# GPUs

View File

@@ -296,21 +296,67 @@
<div class="detail-section wide">
<h4>Storage</h4>
{% set disks = d.get('disk', []) if d.get('disk') else [] %}
{% set partitions = d.get('partition', []) if d.get('partition') else [] %}
{% if disks %}
<table>
<tr class="table-header"><td>Device</td><td>Size</td></tr>
<tr class="table-header"><td>Device</td><td>Mount</td><td>Size</td><td>Used</td><td>Avail</td><td>Use%</td></tr>
{% for disk in disks %}
<tr>
<td>{{ disk.get('name', '-') }}</td>
<td><strong>{{ disk.get('name', '-') }}</strong></td>
<td></td>
<td>{{ disk.get('size_bytes', '')|format_bytes }}</td>
<td></td><td></td><td></td>
</tr>
{% for part in partitions if part.get('parent') == disk.get('name') %}
{% set part_mount = part.get('mount', '') %}
{% set ns = namespace(du=none) %}
{% for du in disk_usages if du.get('mount') == part_mount and part_mount %}
{% set ns.du = du %}
{% endfor %}
<tr>
<td style="padding-left: 20px;">{{ part.get('name', '-') }}</td>
<td>{{ part_mount or '-' }}</td>
<td>{{ part.get('size_bytes', '')|format_bytes }}</td>
{% if ns.du %}
<td>{{ ns.du.get('used_bytes', '')|format_bytes }}</td>
<td>{{ ns.du.get('available_bytes', '')|format_bytes }}</td>
<td>
<span class="disk-pct" style="color: {{ ns.du.get('usage_percent', '0')|float|usage_color }}">
{{ ns.du.get('usage_percent', '-') }}%
</span>
</td>
{% else %}
<td></td><td></td><td></td>
{% endif %}
</tr>
{% endfor %}
</table>
{% endfor %}
{# Show any disk_usage entries not matched to a partition (e.g. NFS, LVM, ZFS) #}
{% for du in disk_usages %}
{% set ns = namespace(matched=false) %}
{% for part in partitions if part.get('mount') == du.get('mount') and part.get('mount') %}
{% set ns.matched = true %}
{% endfor %}
{% if not ns.matched %}
<tr>
<td>{{ du.get('mount', '-') }}</td>
<td>{{ du.get('mount', '-') }}</td>
<td>{{ du.get('total_bytes', '')|format_bytes }}</td>
<td>{{ du.get('used_bytes', '')|format_bytes }}</td>
<td>{{ du.get('available_bytes', '')|format_bytes }}</td>
<td>
<span class="disk-pct" style="color: {{ du.get('usage_percent', '0')|float|usage_color }}">
{{ du.get('usage_percent', '-') }}%
</span>
</td>
</tr>
{% endif %}
{% if disk_usages %}
<table style="margin-top: 8px;">
<tr class="table-header"><td>Mount</td><td>Total</td><td>Used</td><td>Available</td><td>Usage</td></tr>
{% endfor %}
</table>
{% elif disk_usages %}
{# Fallback: no lsblk data (e.g. containers), just show df data #}
<table>
<tr class="table-header"><td>Mount</td><td>Total</td><td>Used</td><td>Avail</td><td>Use%</td></tr>
{% for du in disk_usages %}
<tr>
<td>{{ du.get('mount', '-') }}</td>