2023-09-26 17:12:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
declare -i hwmon_nr_amd=$(( $(cat -n /sys/class/hwmon/hwmon*/name | grep 'amdgpu' | grep -oP '\d+') - 1))
|
|
|
|
|
|
|
|
if (( $hwmon_nr_amd >= 0 )); then
|
|
|
|
hwmon_path="/sys/class/hwmon/hwmon$hwmon_nr_amd"
|
|
|
|
usage=$(cat "$hwmon_path/device/gpu_busy_percent")
|
|
|
|
vram=$(awk '{ print int($1/1024/1024) }' "$hwmon_path/device/mem_info_vram_used")
|
2024-08-06 18:15:24 +02:00
|
|
|
power=$(head -c -7 "$hwmon_path/power1_input")
|
2023-09-26 17:12:28 +02:00
|
|
|
elif which nvidia-smi &> /dev/null; then
|
|
|
|
usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits)
|
|
|
|
vram=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits)
|
|
|
|
power=$(nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits | awk '{ print int($1) }')
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $vram -ge 1024 ]]; then
|
|
|
|
vram=$vram/1024
|
|
|
|
vram_unit="GiB"
|
|
|
|
else
|
|
|
|
vram_unit="MiB"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
{"text": "$usage%", "alt": "", "tooltip": "GPU usage: $usage%\nVRAM usage: ${vram}$vram_unit\nPower draw: ${power}W", "class": "", "percentage": ""}
|
|
|
|
EOF
|