Collect partition info and unify storage table with disk, partition, and usage data
This commit is contained in:
@@ -103,28 +103,36 @@ if [ -n "$total_kb" ] && [ -n "$available_kb" ]; then
|
|||||||
echo "available_mb=$available_mb"
|
echo "available_mb=$available_mb"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Physical disks
|
# Physical disks and partitions
|
||||||
lsblk -b -n -o NAME,SIZE,TYPE 2>/dev/null | while read -r name size type; do
|
lsblk -b -n -P -o NAME,SIZE,TYPE,MOUNTPOINT,PKNAME 2>/dev/null | while read -r line; do
|
||||||
if [ "$type" = "disk" ]; then
|
eval "$line"
|
||||||
echo "[disk:$name]"
|
if [ "$TYPE" = "disk" ]; then
|
||||||
echo "name=$name"
|
echo "[disk:$NAME]"
|
||||||
echo "size_bytes=$size"
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Mounted filesystem usage
|
# Mounted filesystem usage (exclude virtual filesystems)
|
||||||
df -B1 --output=target,size,used,avail,pcent 2>/dev/null | tail -n +2 | while read -r mount total used avail percent; do
|
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
|
case "$mount" in
|
||||||
/|/home|/var|/tmp|/boot|/data*|/mnt*|/srv*|/opt*)
|
/dev|/dev/*|/proc|/proc/*|/sys|/sys/*|/run|/run/*|/snap/*) continue ;;
|
||||||
safename=$(echo "$mount" | tr '/' '_')
|
|
||||||
echo "[disk_usage:${safename}]"
|
|
||||||
echo "mount=$mount"
|
|
||||||
echo "total_bytes=$total"
|
|
||||||
echo "used_bytes=$used"
|
|
||||||
echo "available_bytes=$avail"
|
|
||||||
echo "usage_percent=${percent%\%}"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
safename=$(echo "$mount" | tr '/' '_')
|
||||||
|
echo "[disk_usage:${safename}]"
|
||||||
|
echo "mount=$mount"
|
||||||
|
echo "total_bytes=$total"
|
||||||
|
echo "used_bytes=$used"
|
||||||
|
echo "available_bytes=$avail"
|
||||||
|
echo "usage_percent=${percent%\%}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# GPUs
|
# GPUs
|
||||||
|
|||||||
@@ -296,21 +296,67 @@
|
|||||||
<div class="detail-section wide">
|
<div class="detail-section wide">
|
||||||
<h4>Storage</h4>
|
<h4>Storage</h4>
|
||||||
{% set disks = d.get('disk', []) if d.get('disk') else [] %}
|
{% set disks = d.get('disk', []) if d.get('disk') else [] %}
|
||||||
|
{% set partitions = d.get('partition', []) if d.get('partition') else [] %}
|
||||||
{% if disks %}
|
{% if disks %}
|
||||||
<table>
|
<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 %}
|
{% for disk in disks %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ disk.get('name', '-') }}</td>
|
<td><strong>{{ disk.get('name', '-') }}</strong></td>
|
||||||
|
<td></td>
|
||||||
<td>{{ disk.get('size_bytes', '')|format_bytes }}</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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% 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 %}
|
||||||
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% elif disk_usages %}
|
||||||
|
{# Fallback: no lsblk data (e.g. containers), just show df data #}
|
||||||
{% if disk_usages %}
|
<table>
|
||||||
<table style="margin-top: 8px;">
|
<tr class="table-header"><td>Mount</td><td>Total</td><td>Used</td><td>Avail</td><td>Use%</td></tr>
|
||||||
<tr class="table-header"><td>Mount</td><td>Total</td><td>Used</td><td>Available</td><td>Usage</td></tr>
|
|
||||||
{% for du in disk_usages %}
|
{% for du in disk_usages %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ du.get('mount', '-') }}</td>
|
<td>{{ du.get('mount', '-') }}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user