Add support for Nvidia temperature

This commit is contained in:
Nicolas Mowen 2025-12-31 12:39:36 -07:00
parent 08f95e8274
commit b436ef0649
3 changed files with 17 additions and 3 deletions

View File

@ -246,6 +246,7 @@ async def set_gpu_stats(
"mem": str(round(float(nvidia_usage[i]["mem"]), 2)) + "%",
"enc": str(round(float(nvidia_usage[i]["enc"]), 2)) + "%",
"dec": str(round(float(nvidia_usage[i]["dec"]), 2)) + "%",
"temp": str(nvidia_usage[i]["temp"]),
}
else:

View File

@ -484,10 +484,13 @@ def get_rockchip_npu_stats() -> Optional[dict[str, float | str]]:
return stats
def try_get_info(f, h, default="N/A"):
def try_get_info(f, h, default="N/A", sensor=None):
try:
if h:
v = f(h)
if sensor is not None:
v = f(h, sensor)
else:
v = f(h)
else:
v = f()
except nvml.NVMLError_NotSupported:
@ -516,6 +519,9 @@ def get_nvidia_gpu_stats() -> dict[int, dict]:
util = try_get_info(nvml.nvmlDeviceGetUtilizationRates, handle)
enc = try_get_info(nvml.nvmlDeviceGetEncoderUtilization, handle)
dec = try_get_info(nvml.nvmlDeviceGetDecoderUtilization, handle)
temp = try_get_info(
nvml.nvmlDeviceGetTemperature, handle, default=None, sensor=0
)
pstate = try_get_info(nvml.nvmlDeviceGetPowerState, handle, default=None)
if util != "N/A":
@ -528,6 +534,11 @@ def get_nvidia_gpu_stats() -> dict[int, dict]:
else:
gpu_mem_util = -1
if temp != "N/A" and temp is not None:
temp = float(temp)
else:
temp = None
if enc != "N/A":
enc_util = enc[0]
else:
@ -545,6 +556,7 @@ def get_nvidia_gpu_stats() -> dict[int, dict]:
"enc": enc_util,
"dec": dec_util,
"pstate": pstate or "unknown",
"temp": temp,
}
except Exception:
pass

View File

@ -737,8 +737,9 @@ export default function GeneralMetrics({
<div
className={cn(
"mt-4 grid grid-cols-1 gap-2 sm:grid-cols-2",
gpuEncSeries?.length && "md:grid-cols-4",
gpuTempSeries?.length && "md:grid-cols-3",
gpuEncSeries?.length &&
(gpuTempSeries?.length ? "md:grid-cols-5" : "md:grid-cols-4"),
)}
>
{statsHistory[0]?.gpu_usages && (