From aa4d57202c06f4c776b0d347b188329e1c3cf99f Mon Sep 17 00:00:00 2001
From: zjy <3161362058@qq.com>
Date: Tue, 7 Jan 2025 10:31:28 +0800
Subject: [PATCH] add gpu resource
---
frontend/desktop/src/api/platform.ts | 1 +
.../components/desktop_content/monitor.tsx | 68 +++++++++++--------
.../desktop/src/components/icons/index.tsx | 21 ++++++
.../src/pages/api/desktop/getResource.ts | 7 +-
4 files changed, 69 insertions(+), 28 deletions(-)
diff --git a/frontend/desktop/src/api/platform.ts b/frontend/desktop/src/api/platform.ts
index b37d0347a52..313000b532f 100644
--- a/frontend/desktop/src/api/platform.ts
+++ b/frontend/desktop/src/api/platform.ts
@@ -92,6 +92,7 @@ export const getResource = () => {
totalMemory: string;
totalStorage: string;
runningPodCount: string;
+ totalGpuCount: string;
totalPodCount: string;
}>
>('/api/desktop/getResource');
diff --git a/frontend/desktop/src/components/desktop_content/monitor.tsx b/frontend/desktop/src/components/desktop_content/monitor.tsx
index 53c7d0b791a..5cbeaf58d5a 100644
--- a/frontend/desktop/src/components/desktop_content/monitor.tsx
+++ b/frontend/desktop/src/components/desktop_content/monitor.tsx
@@ -3,8 +3,9 @@ import { Box, CircularProgress, CircularProgressLabel, Flex, Text } from '@chakr
import { MonitorIcon } from '@sealos/ui';
import { useQuery } from '@tanstack/react-query';
import { useTranslation } from 'next-i18next';
-import { CpuIcon, FlowIcon, MemoryIcon, StorageIcon } from '../icons';
+import { CpuIcon, FlowIcon, GpuIcon, MemoryIcon, StorageIcon } from '../icons';
import { blurBackgroundStyles } from './index';
+import { useMemo } from 'react';
export default function Monitor({ needStyles = true }: { needStyles?: boolean }) {
const { t } = useTranslation();
@@ -12,32 +13,45 @@ export default function Monitor({ needStyles = true }: { needStyles?: boolean })
staleTime: 60 * 1000
});
- const info = [
- {
- label: 'CPU',
- value: data?.data?.totalCpu,
- icon: ,
- unit: 'C'
- },
- {
- label: t('common:memory'),
- value: data?.data?.totalMemory,
- icon: ,
- unit: 'GB'
- },
- {
- label: t('common:storage'),
- value: data?.data?.totalStorage,
- icon: ,
- unit: 'GB'
- },
- {
- label: t('common:flow'),
- value: `~`,
- icon: ,
- unit: 'GB'
- }
- ];
+ const info = useMemo(
+ () => [
+ {
+ label: 'CPU',
+ value: data?.data?.totalCpu,
+ icon: ,
+ unit: 'C'
+ },
+ {
+ label: t('common:memory'),
+ value: data?.data?.totalMemory,
+ icon: ,
+ unit: 'GB'
+ },
+ {
+ label: t('common:storage'),
+ value: data?.data?.totalStorage,
+ icon: ,
+ unit: 'GB'
+ },
+ {
+ label: t('common:flow'),
+ value: `~`,
+ icon: ,
+ unit: 'GB'
+ },
+ ...(Number(data?.data?.totalGpuCount) > 0
+ ? [
+ {
+ label: 'GPU',
+ value: data?.data?.totalGpuCount,
+ icon: ,
+ unit: 'Card'
+ }
+ ]
+ : [])
+ ],
+ [data?.data, t]
+ );
const totalPodCount = Number(data?.data?.totalPodCount) || 0;
const runningPodCount = Number(data?.data?.runningPodCount) || 0;
diff --git a/frontend/desktop/src/components/icons/index.tsx b/frontend/desktop/src/components/icons/index.tsx
index 5e42b63ca27..54aa7322e44 100644
--- a/frontend/desktop/src/components/icons/index.tsx
+++ b/frontend/desktop/src/components/icons/index.tsx
@@ -605,3 +605,24 @@ export function AttachmentIcon(props: IconProps) {
);
}
+
+export function GpuIcon(props: IconProps) {
+ return (
+
+
+
+
+
+ );
+}
diff --git a/frontend/desktop/src/pages/api/desktop/getResource.ts b/frontend/desktop/src/pages/api/desktop/getResource.ts
index 8e569580b53..784281b5975 100644
--- a/frontend/desktop/src/pages/api/desktop/getResource.ts
+++ b/frontend/desktop/src/pages/api/desktop/getResource.ts
@@ -23,6 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
let totalMemoryLimits = 0;
let totalStorageRequests = 0;
let runningPodCount = 0;
+ let totalGpuCount = 0;
let totalPodCount = 0;
for (const pod of result.body.items) {
@@ -40,9 +41,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const limits = container?.resources.limits as {
cpu: string;
memory: string;
+ ['nvidia.com/gpu']?: string;
};
totalCpuLimits += parseResourceValue(limits.cpu);
totalMemoryLimits += parseResourceValue(limits.memory);
+
+ totalGpuCount += Number(limits['nvidia.com/gpu'] || 0);
}
if (!pod?.spec?.volumes) continue;
@@ -65,7 +69,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
totalMemory: totalMemoryLimits.toFixed(2),
totalStorage: totalStorageRequests.toFixed(2),
runningPodCount,
- totalPodCount
+ totalPodCount,
+ totalGpuCount
// result: result.body.items
}
});