dotfiles/private_dot_config/waybar/scripts/gpu-usage/gpu-usage.py

16 lines
396 B
Python
Raw Permalink Normal View History

from subprocess import check_output
import json
gpu_usage = check_output(["nvidia-smi", "--query-gpu=utilization.gpu", "--format=csv,noheader,nounits"])
gpu_usage = gpu_usage.decode('utf-8').replace("\n",'')
return_json = {
"text":gpu_usage,
"alt":"GPU_PERCENT",
"tooltip":"GPU percentage",
"class":"gpu_class",
"percentage":int(gpu_usage)
}
print(json.dumps(return_json))