Add GPU PCI ID fallback names and container passthrough indicators
This commit is contained in:
@@ -135,13 +135,15 @@ df -B1 --output=target,size,used,avail,pcent \
|
||||
echo "usage_percent=${percent%\%}"
|
||||
done
|
||||
|
||||
# GPUs
|
||||
# GPUs (use -nn for numeric PCI IDs as fallback for outdated pciid databases)
|
||||
gpu_idx=0
|
||||
while read -r line; do
|
||||
echo "[gpu:$gpu_idx]"
|
||||
echo "description=$line"
|
||||
pci_addr=$(echo "$line" | awk '{print $1}')
|
||||
echo "pci_address=$pci_addr"
|
||||
gpu_idx=$((gpu_idx + 1))
|
||||
done < <(lspci 2>/dev/null | grep -iE 'vga|3d|display')
|
||||
done < <(lspci -nn 2>/dev/null | grep -iE 'vga|3d|display')
|
||||
|
||||
# GPU utilization (NVIDIA)
|
||||
if command -v nvidia-smi &>/dev/null; then
|
||||
@@ -171,6 +173,10 @@ if [ -n "$igpu_cmd" ]; then
|
||||
igpu_raw=$(timeout 2 $igpu_prefix intel_gpu_top -J -s 500 -d /dev/dri/"$card" 2>/dev/null)
|
||||
if [ -n "$igpu_raw" ]; then
|
||||
echo "[intel_gpu:$igpu_idx]"
|
||||
pci_addr=$(basename "$(readlink "$drm/device" 2>/dev/null)" 2>/dev/null)
|
||||
[ -n "$pci_addr" ] && echo "pci_address=$pci_addr"
|
||||
gpu_desc=$(lspci -nn -s "$pci_addr" 2>/dev/null)
|
||||
[ -n "$gpu_desc" ] && echo "name=$gpu_desc"
|
||||
busy=$(echo "$igpu_raw" | grep -oP '"busy"\s*:\s*\K[0-9.]+' | sort -rn | head -1)
|
||||
echo "utilization_percent=${busy:-0}"
|
||||
freq=$(echo "$igpu_raw" | grep -oP '"actual"\s*:\s*\K[0-9.]+' | head -1)
|
||||
@@ -292,6 +298,31 @@ if command -v pct &>/dev/null; then
|
||||
if [ "$status" = "running" ]; then
|
||||
gather_container_stats "_sudo pct exec $vmid --"
|
||||
fi
|
||||
# Check for GPU/device passthrough in LXC config
|
||||
if [ -f "/etc/pve/lxc/${vmid}.conf" ]; then
|
||||
pt_addrs=""
|
||||
while read -r dev_line; do
|
||||
dev_path=$(echo "$dev_line" | sed 's/dev[0-9]*: *//' | cut -d, -f1)
|
||||
case "$dev_path" in
|
||||
/dev/dri/card*)
|
||||
card_name=$(basename "$dev_path")
|
||||
pci=$(basename "$(readlink "/sys/class/drm/$card_name/device" 2>/dev/null)" 2>/dev/null)
|
||||
if [ -n "$pci" ] && ! echo "$pt_addrs" | grep -q "$pci"; then
|
||||
pt_addrs="${pt_addrs:+$pt_addrs,}$pci"
|
||||
fi
|
||||
;;
|
||||
/dev/dri/renderD*)
|
||||
render_minor=$(basename "$dev_path" | grep -oE '[0-9]+')
|
||||
card_num=$((render_minor - 128))
|
||||
pci=$(basename "$(readlink "/sys/class/drm/card${card_num}/device" 2>/dev/null)" 2>/dev/null)
|
||||
if [ -n "$pci" ] && ! echo "$pt_addrs" | grep -q "$pci"; then
|
||||
pt_addrs="${pt_addrs:+$pt_addrs,}$pci"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done < <(grep -E '^dev[0-9]+:' "/etc/pve/lxc/${vmid}.conf" 2>/dev/null)
|
||||
[ -n "$pt_addrs" ] && echo "gpu_passthrough=$pt_addrs"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -313,6 +344,13 @@ if command -v qm &>/dev/null; then
|
||||
gather_container_stats "_sudo qm guest exec $vmid --"
|
||||
fi
|
||||
fi
|
||||
# Get PCI passthrough devices from VM config
|
||||
pt_addrs=""
|
||||
while read -r pci_line; do
|
||||
pci_dev=$(echo "$pci_line" | sed 's/hostpci[0-9]*: *//' | cut -d, -f1)
|
||||
[ -n "$pci_dev" ] && pt_addrs="${pt_addrs:+$pt_addrs,}$pci_dev"
|
||||
done < <(_sudo qm config "$vmid" 2>/dev/null | grep -E '^hostpci[0-9]+:')
|
||||
[ -n "$pt_addrs" ] && echo "gpu_passthrough=$pt_addrs"
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user