修改前端gpu显示页面
Change-Id: I98e2c0b9dd775f6e7c61c294808666ff7c23f224
diff --git a/Merge/front/src/api/posts_trm.js b/Merge/front/src/api/posts_trm.js
index 8f7e877..2c0fc14 100644
--- a/Merge/front/src/api/posts_trm.js
+++ b/Merge/front/src/api/posts_trm.js
@@ -218,7 +218,11 @@
* @returns Promise<[ {id, gpu_id, gpu_usage, gpu_memory_usage, timestamp}, … ]>
*/
export async function fetchGpuUsage(limit = 100) {
- const token = localStorage.getItem('token')
+ const token = getAuthToken()
+ if (!token || token === 'null') {
+ throw new Error('Token not found or invalid. Please login again.')
+ }
+
const res = await fetch(`http://10.126.59.25:8082/gpu-usage?limit=${limit}`, {
method: 'GET',
headers: {
diff --git a/Merge/front/src/components/PerformanceLogs.js b/Merge/front/src/components/PerformanceLogs.js
index 67518de..f0f3d9f 100644
--- a/Merge/front/src/components/PerformanceLogs.js
+++ b/Merge/front/src/components/PerformanceLogs.js
@@ -18,6 +18,12 @@
const fetchSystemData = fetchSysCost(userId)
.then(result => {
// 检查是否是权限错误
+ if (typeof result === 'string' && result.startsWith('<!DOCTYPE')) {
+ // 返回的是 HTML,说明未登录或接口错误
+ setUnauthorized(true);
+ setData([]);
+ return;
+ }
if (result && result.status === 'error' && result.message === 'Unauthorized') {
setUnauthorized(true);
setData([]);
@@ -57,6 +63,11 @@
// 获取GPU数据
const fetchGpuData = fetchGpuUsage(100)
.then(result => {
+ if (typeof result === 'string' && result.startsWith('<!DOCTYPE')) {
+ // 返回的是 HTML,说明未登录或接口错误
+ setGpuData([]);
+ return;
+ }
console.log('GPU data:', result);
const processedData = processGpuData(result);
setGpuData(processedData);
@@ -180,7 +191,7 @@
/>
<YAxis domain={[0, 100]} label={{ value: '使用率 (%)', angle: -90, position: 'insideLeft' }} />
<Tooltip
- formatter={(val, name) => [`${val?.toFixed(2)}%`, name]}
+ formatter={(val, name) => [`${val != null && typeof val === 'number' ? val.toFixed(2) : val}%`, name]}
labelFormatter={ts => new Date(ts).toLocaleString()}
/>
<Legend />
@@ -212,7 +223,7 @@
/>
<YAxis domain={[0, 'auto']} label={{ value: '内存 (MB)', angle: -90, position: 'insideLeft' }} />
<Tooltip
- formatter={(val, name) => [`${val?.toFixed(2)} MB`, name]}
+ formatter={(val, name) => [`${val != null && typeof val === 'number' ? val.toFixed(2) : val} MB`, name]}
labelFormatter={ts => new Date(ts).toLocaleString()}
/>
<Legend />