Skip to content

Instantly share code, notes, and snippets.

@jpsutton
Created September 5, 2023 20:34
Show Gist options
  • Save jpsutton/8734ce209f7874d5e386d2865c1adc8a to your computer and use it in GitHub Desktop.
Save jpsutton/8734ce209f7874d5e386d2865c1adc8a to your computer and use it in GitHub Desktop.
Reading an Nvidia GPU temperature value from a libvirt Windows guest
#!/bin/bash
GUEST_NAME=Win10_With_GPU
job_exited="false"
exec_result=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec", "arguments": { "path": "nvidia-smi.exe", "arg": [ "--format=csv,noheader", "--query-gpu=temperature.gpu" ], "capture-output": true }}')
exec_pid=$(echo "$exec_result" | jq ".return.pid")
while [ "$job_exited" == "false" ]; do
exec_job_data=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec-status", "arguments": { "pid": '" ${exec_pid}}}")
job_exited=$(echo "$exec_job_data" | jq '.return.exited')
if [ "$job_exited" == "false" ]; then
sleep .1s
continue
fi
echo "$exec_job_data" | jq '.return["out-data"]' | tr -d '"' | base64 --decode
break
done
@jpsutton
Copy link
Author

jpsutton commented Sep 5, 2023

This Bash script executes the "nvidia-smi.exe" utility on a Windows-based guest to extract the GPU temperature value of an Nvidia GPU passed through to that guest. This script requires the Qemu Guest Agent to be installed on the guest, as well as the appropriate agent channel to be configured in the libvirt guest XML definition.

@pallaswept
Copy link

Props for helping bring this feature to CoolerControl. I don't think I'll ever need it myself, but it is very nice of you :)

@jpsutton
Copy link
Author

jpsutton commented Sep 7, 2023

@pallaswept don't thank me yet for CoolerControl; the code's not written yet ;)

@pallaswept
Copy link

It's the thought that counts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment