From 16d2ede5c4b979016e8ee45f2d22889e600d98d1 Mon Sep 17 00:00:00 2001 From: bkbilly Date: Sat, 21 Jan 2023 22:23:42 +0200 Subject: [PATCH] Nvidia GPU info #18 --- lnxlink/consts.py | 1 + lnxlink/modules/nvidia_gpu.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lnxlink/modules/nvidia_gpu.py diff --git a/lnxlink/consts.py b/lnxlink/consts.py index d150029..bbc7e2d 100644 --- a/lnxlink/consts.py +++ b/lnxlink/consts.py @@ -67,4 +67,5 @@ - bash - required_restart - disk_usage +- nvidia_gpu """ diff --git a/lnxlink/modules/nvidia_gpu.py b/lnxlink/modules/nvidia_gpu.py new file mode 100644 index 0000000..0cbbe3a --- /dev/null +++ b/lnxlink/modules/nvidia_gpu.py @@ -0,0 +1,24 @@ +import subprocess + + +class Addon(): + name = 'Nvidia GPU' + icon = 'mdi:expansion-card-variant' + unit = 'json' + + def getInfo(self) -> dict: + stdout = subprocess.run( + ['nvidia-smi', + '--query-gpu=driver_version,name,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,power.draw,clocks.current.graphics', + '--format=csv,nounits'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).stdout.decode("UTF-8").strip().split('\n') + # stdout = map(int, stdout.split(',')) + headers = stdout[0].split(', ') + values = stdout[1].split(', ') + + gpu_status = {} + for num, header in enumerate(headers): + gpu_status[header] = values[num] + gpu_status['status'] = gpu_status['name'] + return gpu_status