add gpuusage的逻辑
Change-Id: Ie1634a7d58ab94b05a3ebd7de87d362ca9be2286
diff --git a/Merge/front/src/api/posts_trm.js b/Merge/front/src/api/posts_trm.js
index d6303a7..8f7e877 100644
--- a/Merge/front/src/api/posts_trm.js
+++ b/Merge/front/src/api/posts_trm.js
@@ -209,4 +209,30 @@
}
console.log('Normalized sys cost list:', list)
return list
+}
+
+/**
+ * 获取GPU使用情况数据
+ * GET /gpu-usage
+ * @param {number} limit 获取记录条数,默认100条
+ * @returns Promise<[ {id, gpu_id, gpu_usage, gpu_memory_usage, timestamp}, … ]>
+ */
+export async function fetchGpuUsage(limit = 100) {
+ const token = localStorage.getItem('token')
+ const res = await fetch(`http://10.126.59.25:8082/gpu-usage?limit=${limit}`, {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${token}`
+ }
+ })
+ if (!res.ok) throw new Error(`fetchGpuUsage: ${res.status}`)
+ const json = await res.json()
+ console.log('fetchGpuUsage response:', json)
+
+ if (json.success === false) {
+ throw new Error(json.message || 'Failed to fetch GPU usage')
+ }
+
+ return json.data?.records || []
}
\ No newline at end of file