From ed99c3c0c808f02c44282f6ef02a06a82f6edd06 Mon Sep 17 00:00:00 2001 From: Jaret Burkett Date: Sat, 22 Feb 2025 12:43:20 -0700 Subject: [PATCH] Moved gpu to its own widget --- ui/src/components/GPUMonitor.tsx | 98 +------------------------------- ui/src/components/GPUWidget.tsx | 95 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 96 deletions(-) create mode 100644 ui/src/components/GPUWidget.tsx diff --git a/ui/src/components/GPUMonitor.tsx b/ui/src/components/GPUMonitor.tsx index 9c06422f..f470acf0 100644 --- a/ui/src/components/GPUMonitor.tsx +++ b/ui/src/components/GPUMonitor.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { GPUApiResponse } from '@/types'; import Loading from '@/components/Loading'; +import GPUWidget from '@/components/GPUWidget'; const GpuMonitor: React.FC = () => { const [gpuData, setGpuData] = useState(null); @@ -39,35 +40,6 @@ const GpuMonitor: React.FC = () => { return () => clearInterval(intervalId); }, []); - // Helper to format memory values - const formatMemory = (mb: number): string => { - if (mb >= 1024) { - return `${(mb / 1024).toFixed(2)} GB`; - } - return `${mb} MB`; - }; - - // Helper to determine background color based on utilization - const getUtilizationColor = (percent: number): string => { - if (percent < 30) return 'bg-green-100'; - if (percent < 70) return 'bg-yellow-100'; - return 'bg-red-100'; - }; - - // Helper to determine text color based on utilization - const getUtilizationTextColor = (percent: number): string => { - if (percent < 30) return 'text-green-800'; - if (percent < 70) return 'text-yellow-800'; - return 'text-red-800'; - }; - - // Helper to determine temperature color - const getTemperatureColor = (temp: number): string => { - if (temp < 50) return 'text-green-600'; - if (temp < 80) return 'text-yellow-600'; - return 'text-red-600'; - }; - if (loading) { return ; } @@ -116,73 +88,7 @@ const GpuMonitor: React.FC = () => {
{gpuData.gpus.map(gpu => ( -
-
-

{gpu.name}

- GPU #{gpu.index} -
- -
-
-

Temperature:

-

{gpu.temperature}°C

-
- -
-

GPU Utilization

-
-
-
-

{gpu.utilization.gpu}%

-
- -
-

Memory Utilization

-
-
-
-
- - {formatMemory(gpu.memory.used)} / {formatMemory(gpu.memory.total)} - - {((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}% -
-
- -
-
-

Power

-

- {gpu.power.draw.toFixed(1)}W / {gpu.power.limit.toFixed(1)}W -

-
-
-

Memory Clock

-

{gpu.clocks.memory} MHz

-
-
- -
-
-

Graphics Clock

-

{gpu.clocks.graphics} MHz

-
-
-

Driver Version

-

{gpu.driverVersion}

-
-
-
-
+ ))}
diff --git a/ui/src/components/GPUWidget.tsx b/ui/src/components/GPUWidget.tsx new file mode 100644 index 00000000..f6496c6e --- /dev/null +++ b/ui/src/components/GPUWidget.tsx @@ -0,0 +1,95 @@ +import React, { useState } from 'react'; +import { GpuInfo } from '@/types'; + +interface GPUWidgetProps { + gpu: GpuInfo; +} + +export default function GPUWidget({ gpu }: GPUWidgetProps) { + // Helper to format memory values + const formatMemory = (mb: number): string => { + if (mb >= 1024) { + return `${(mb / 1024).toFixed(2)} GB`; + } + return `${mb} MB`; + }; + + // Helper to determine temperature color + const getTemperatureColor = (temp: number): string => { + if (temp < 50) return 'text-green-600'; + if (temp < 80) return 'text-yellow-600'; + return 'text-red-600'; + }; + + return ( + <> +
+
+

{gpu.name}

+ GPU #{gpu.index} +
+ +
+
+

Temperature:

+

{gpu.temperature}°C

+
+ +
+

GPU Utilization

+
+
+
+

{gpu.utilization.gpu}%

+
+ +
+

Memory Utilization

+
+
+
+
+ + {formatMemory(gpu.memory.used)} / {formatMemory(gpu.memory.total)} + + {((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}% +
+
+ +
+
+

Power

+

+ {gpu.power.draw.toFixed(1)}W / {gpu.power.limit.toFixed(1)}W +

+
+
+

Memory Clock

+

{gpu.clocks.memory} MHz

+
+
+ +
+
+

Graphics Clock

+

{gpu.clocks.graphics} MHz

+
+
+

Driver Version

+

{gpu.driverVersion}

+
+
+
+
+ + ); +}