GPU检测修改
This commit is contained in:
@@ -1721,8 +1721,69 @@
|
||||
let refreshTimer = null;
|
||||
let currentRefreshInterval = 5000;
|
||||
|
||||
// 刷新硬件信息
|
||||
function refreshHardwareInfo() {
|
||||
// 刷新硬件信息(使用真实API)
|
||||
async function refreshHardwareInfo() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/system-info`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 0 && result.data) {
|
||||
const data = result.data;
|
||||
|
||||
// 更新CPU
|
||||
const cpu = data.cpu || {};
|
||||
const cpuPercent = cpu.percent || 0;
|
||||
document.getElementById('cpuPercent').textContent = cpuPercent + '%';
|
||||
document.getElementById('cpuBar').style.width = cpuPercent + '%';
|
||||
document.getElementById('cpuCores').textContent = (cpu.cores || 0) + ' 核心';
|
||||
|
||||
// 更新内存
|
||||
const mem = data.memory || {};
|
||||
const memUsed = mem.used_gb || 0;
|
||||
const memTotal = mem.total_gb || 0;
|
||||
const memPercent = mem.percent || 0;
|
||||
document.getElementById('memoryPercent').textContent = memPercent + '%';
|
||||
document.getElementById('memoryBar').style.width = memPercent + '%';
|
||||
document.getElementById('memoryUsed').textContent = memUsed + ' GB';
|
||||
document.getElementById('memoryAvailable').textContent = (mem.available_gb || 0) + ' GB';
|
||||
document.getElementById('memoryCached').textContent = (mem.cached_gb || 0) + ' GB';
|
||||
|
||||
// 更新磁盘
|
||||
const disk = data.disk || {};
|
||||
const diskUsed = disk.used_gb || 0;
|
||||
const diskTotal = disk.total_gb || 0;
|
||||
const diskPercent = disk.percent || 0;
|
||||
document.getElementById('diskPercent').textContent = diskPercent + '%';
|
||||
document.getElementById('diskBar').style.width = diskPercent + '%';
|
||||
document.getElementById('diskUsed').textContent = diskUsed + ' GB';
|
||||
document.getElementById('diskAvailable').textContent = (diskTotal - diskUsed) + ' GB';
|
||||
|
||||
// 更新网络
|
||||
const net = data.network || {};
|
||||
document.getElementById('totalDownload').textContent = (net.download_mb || 0) + ' GB';
|
||||
document.getElementById('totalUpload').textContent = (net.upload_mb || 0) + ' GB';
|
||||
|
||||
// 更新系统信息
|
||||
const sys = data.system || {};
|
||||
const uptime = sys.uptime_seconds || 0;
|
||||
const days = Math.floor(uptime / 86400);
|
||||
const hours = Math.floor((uptime % 86400) / 3600);
|
||||
const mins = Math.floor((uptime % 3600) / 60);
|
||||
document.getElementById('uptime').textContent = days + ' 天 ' + hours + ' 时 ' + mins + ' 分';
|
||||
document.getElementById('processCount').textContent = sys.process_count || 0;
|
||||
|
||||
// 更新GPU信息(传入真实数据)
|
||||
updateGPUInfo(data.gpu || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取系统信息失败:', error);
|
||||
// 如果API调用失败,使用模拟数据作为后备
|
||||
useMockData();
|
||||
}
|
||||
}
|
||||
|
||||
// 使用模拟数据(当API不可用时)
|
||||
function useMockData() {
|
||||
// 更新CPU
|
||||
const cpuUsage = Math.floor(Math.random() * 30) + 20;
|
||||
document.getElementById('cpuPercent').textContent = cpuUsage + '%';
|
||||
@@ -1768,10 +1829,6 @@
|
||||
document.getElementById('uptime').textContent = days + ' 天 ' + hours + ' 时 ' + mins + ' 分';
|
||||
document.getElementById('processCount').textContent = Math.floor(Math.random() * 200 + 100);
|
||||
document.getElementById('loadAvg').textContent = (Math.random() * 2).toFixed(2) + ', ' + (Math.random() * 1.5).toFixed(2) + ', ' + (Math.random() * 1).toFixed(2);
|
||||
|
||||
// 更新时间
|
||||
// const now = new Date();
|
||||
// document.getElementById('updateTime').textContent = now.toLocaleTimeString('zh-CN');
|
||||
}
|
||||
|
||||
// GPU配置 - 支持模拟1-8块GPU
|
||||
@@ -1787,95 +1844,167 @@
|
||||
{ name: 'NVIDIA RTX 4080', memory: 16 }
|
||||
];
|
||||
|
||||
// 初始化GPU列表
|
||||
function initGPUList() {
|
||||
const gpuList = document.getElementById('gpuList');
|
||||
const gpuCount = Math.min(GPU_COUNT, 8);
|
||||
document.getElementById('gpuCount').textContent = `检测到 ${gpuCount} 块 GPU`;
|
||||
|
||||
let gpuCardsHTML = '';
|
||||
for (let i = 0; i < gpuCount; i++) {
|
||||
const config = gpuConfigs[i % gpuConfigs.length];
|
||||
gpuCardsHTML += `
|
||||
<div class="border border-gray-200 rounded-lg p-2 bg-gradient-to-br from-gray-50 to-gray-100" id="gpuCard${i}">
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<div class="flex items-center min-w-0">
|
||||
<div class="w-6 h-6 rounded bg-red-100 flex items-center justify-center mr-2 flex-shrink-0">
|
||||
<i class="fa fa-microchip text-red-600 text-xs"></i>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="text-xs font-medium text-gray-800 truncate" id="gpuName${i}" title="${config.name}">${config.name}</div>
|
||||
<div class="text-[10px] text-gray-400">PCIe ${Math.floor(Math.random() * 4 + 1)}:00.0</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right flex-shrink-0 ml-2">
|
||||
<span class="text-sm font-bold text-gray-800" id="gpuPercent${i}">0%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="relative h-1.5 bg-gray-200 rounded-full overflow-hidden mb-2">
|
||||
<div id="gpuBar${i}" class="absolute left-0 top-0 h-full bg-gradient-to-r from-green-400 via-yellow-400 to-red-400 transition-all duration-500" style="width: 0%"></div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 gap-1 text-center text-[10px]">
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">显存</div>
|
||||
<div class="font-medium text-gray-700 truncate" id="gpuMem${i}" title="0/${config.memory} GB">0/${config.memory}G</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">温度</div>
|
||||
<div class="font-medium text-gray-700" id="gpuTemp${i}">0°C</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">功耗</div>
|
||||
<div class="font-medium text-gray-700" id="gpuPower${i}">0W</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">Fan</div>
|
||||
<div class="font-medium text-gray-700" id="gpuFan${i}">0%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
// 初始化GPU列表(获取真实数据)
|
||||
async function initGPUList() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/system-info`);
|
||||
const result = await response.json();
|
||||
const gpuData = (result.data && result.data.gpu) || [];
|
||||
updateGPUInfo(gpuData);
|
||||
} catch (error) {
|
||||
console.error('初始化GPU列表失败:', error);
|
||||
useMockGPUData();
|
||||
}
|
||||
gpuList.innerHTML = gpuCardsHTML;
|
||||
}
|
||||
|
||||
// 更新GPU信息
|
||||
function updateGPUInfo() {
|
||||
function updateGPUInfo(gpuData) {
|
||||
// 如果有真实数据,使用真实数据
|
||||
if (gpuData && gpuData.length > 0) {
|
||||
const gpuCount = gpuData.length;
|
||||
document.getElementById('gpuCount').textContent = `检测到 ${gpuCount} 块 GPU`;
|
||||
|
||||
let totalUsedMemory = 0;
|
||||
let totalMemory = 0;
|
||||
|
||||
// 重新初始化GPU列表
|
||||
const gpuList = document.getElementById('gpuList');
|
||||
if (gpuList) {
|
||||
let gpuCardsHTML = '';
|
||||
for (let i = 0; i < gpuCount; i++) {
|
||||
const gpu = gpuData[i];
|
||||
totalUsedMemory += gpu.memory_used_gb;
|
||||
totalMemory += gpu.memory_total_gb;
|
||||
|
||||
gpuCardsHTML += `
|
||||
<div class="border border-gray-200 rounded-lg p-2 bg-gradient-to-br from-gray-50 to-gray-100" id="gpuCard${i}">
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<div class="flex items-center min-w-0">
|
||||
<div class="w-6 h-6 rounded bg-red-100 flex items-center justify-center mr-2 flex-shrink-0">
|
||||
<i class="fa fa-microchip text-red-600 text-xs"></i>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="text-xs font-medium text-gray-800 truncate" id="gpuName${i}" title="${gpu.name}">${gpu.name}</div>
|
||||
<div class="text-[10px] text-gray-400">PCIe</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right flex-shrink-0 ml-2">
|
||||
<span class="text-sm font-bold text-gray-800" id="gpuPercent${i}">${gpu.gpu_percent}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="relative h-1.5 bg-gray-200 rounded-full overflow-hidden mb-2">
|
||||
<div id="gpuBar${i}" class="absolute left-0 top-0 h-full bg-gradient-to-r from-green-400 via-yellow-400 to-red-400 transition-all duration-500" style="width: ${gpu.gpu_percent}%"></div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 gap-1 text-center text-[10px]">
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">显存</div>
|
||||
<div class="font-medium text-gray-700" id="gpuMem${i}">${gpu.memory_used_gb}/${gpu.memory_total_gb} GB</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">温度</div>
|
||||
<div class="font-medium ${gpu.temperature >= 80 ? 'text-red-600' : gpu.temperature >= 70 ? 'text-yellow-600' : 'text-gray-800'}" id="gpuTemp${i}">${gpu.temperature}°C</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">功耗</div>
|
||||
<div class="font-medium text-gray-700" id="gpuPower${i}">${gpu.power_w} W</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">Fan</div>
|
||||
<div class="font-medium text-gray-700" id="gpuFan${i}">${gpu.fan_speed || 0}%</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1 grid grid-cols-2 gap-1 text-center text-[9px] text-gray-400">
|
||||
<div>Clock: <span id="gpuClock${i}">${gpu.clock_mhz || 0} MHz</span></div>
|
||||
<div>Driver: <span id="gpuDriver${i}">${gpu.driver_version || '-'}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
gpuList.innerHTML = gpuCardsHTML;
|
||||
}
|
||||
|
||||
// 更新总显存
|
||||
const gpuTotalMem = document.getElementById('gpuTotalMemory');
|
||||
if (gpuTotalMem) {
|
||||
gpuTotalMem.textContent = `${totalUsedMemory}/${totalMemory} GB`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 没有真实数据,使用模拟数据
|
||||
useMockGPUData();
|
||||
}
|
||||
|
||||
// 使用模拟GPU数据
|
||||
function useMockGPUData() {
|
||||
const gpuCount = Math.min(GPU_COUNT, 8);
|
||||
let totalUsedMemory = 0;
|
||||
let totalMemory = 0;
|
||||
|
||||
for (let i = 0; i < gpuCount; i++) {
|
||||
const config = gpuConfigs[i % gpuConfigs.length];
|
||||
const gpuUsage = Math.floor(Math.random() * 60 + 20);
|
||||
const memUsed = (Math.random() * config.memory * 0.7 + config.memory * 0.1).toFixed(1);
|
||||
const temp = Math.floor(Math.random() * 30 + 40);
|
||||
const power = Math.floor(Math.random() * 150 + 100);
|
||||
const fan = Math.floor(gpuUsage + Math.random() * 10);
|
||||
// 重新初始化GPU列表
|
||||
const gpuList = document.getElementById('gpuList');
|
||||
if (gpuList) {
|
||||
let gpuCardsHTML = '';
|
||||
for (let i = 0; i < gpuCount; i++) {
|
||||
const config = gpuConfigs[i % gpuConfigs.length];
|
||||
const gpuUsage = Math.floor(Math.random() * 60 + 20);
|
||||
const memUsed = (Math.random() * config.memory * 0.7 + config.memory * 0.1).toFixed(1);
|
||||
const temp = Math.floor(Math.random() * 30 + 40);
|
||||
const power = Math.floor(Math.random() * 150 + 100);
|
||||
const fan = Math.floor(gpuUsage + Math.random() * 10);
|
||||
|
||||
totalUsedMemory += parseFloat(memUsed);
|
||||
totalMemory += config.memory;
|
||||
totalUsedMemory += parseFloat(memUsed);
|
||||
totalMemory += config.memory;
|
||||
|
||||
document.getElementById(`gpuPercent${i}`).textContent = gpuUsage + '%';
|
||||
document.getElementById(`gpuBar${i}`).style.width = gpuUsage + '%';
|
||||
document.getElementById(`gpuMem${i}`).textContent = `${parseFloat(memUsed).toFixed(1)}/${config.memory} GB`;
|
||||
document.getElementById(`gpuTemp${i}`).textContent = temp + '°C';
|
||||
document.getElementById(`gpuPower${i}`).textContent = power + ' W';
|
||||
document.getElementById(`gpuFan${i}`).textContent = fan + '%';
|
||||
|
||||
// 根据温度改变颜色
|
||||
const tempEl = document.getElementById(`gpuTemp${i}`);
|
||||
if (temp >= 80) {
|
||||
tempEl.className = 'font-medium text-red-600';
|
||||
} else if (temp >= 70) {
|
||||
tempEl.className = 'font-medium text-yellow-600';
|
||||
} else {
|
||||
tempEl.className = 'font-medium text-gray-800';
|
||||
gpuCardsHTML += `
|
||||
<div class="border border-gray-200 rounded-lg p-2 bg-gradient-to-br from-gray-50 to-gray-100" id="gpuCard${i}">
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<div class="flex items-center min-w-0">
|
||||
<div class="w-6 h-6 rounded bg-red-100 flex items-center justify-center mr-2 flex-shrink-0">
|
||||
<i class="fa fa-microchip text-red-600 text-xs"></i>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="text-xs font-medium text-gray-800 truncate" id="gpuName${i}" title="${config.name}">${config.name}</div>
|
||||
<div class="text-[10px] text-gray-400">PCIe ${Math.floor(Math.random() * 4 + 1)}:00.0</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right flex-shrink-0 ml-2">
|
||||
<span class="text-sm font-bold text-gray-800" id="gpuPercent${i}">${gpuUsage}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="relative h-1.5 bg-gray-200 rounded-full overflow-hidden mb-2">
|
||||
<div id="gpuBar${i}" class="absolute left-0 top-0 h-full bg-gradient-to-r from-green-400 via-yellow-400 to-red-400 transition-all duration-500" style="width: ${gpuUsage}%"></div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 gap-1 text-center text-[10px]">
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">显存</div>
|
||||
<div class="font-medium text-gray-700" id="gpuMem${i}">${parseFloat(memUsed).toFixed(1)}/${config.memory} GB</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">温度</div>
|
||||
<div class="font-medium ${temp >= 80 ? 'text-red-600' : temp >= 70 ? 'text-yellow-600' : 'text-gray-800'}" id="gpuTemp${i}">${temp}°C</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">功耗</div>
|
||||
<div class="font-medium text-gray-700" id="gpuPower${i}">${power} W</div>
|
||||
</div>
|
||||
<div class="bg-white/80 rounded py-0.5">
|
||||
<div class="text-gray-400">Fan</div>
|
||||
<div class="font-medium text-gray-700" id="gpuFan${i}">${fan}%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
gpuList.innerHTML = gpuCardsHTML;
|
||||
document.getElementById('gpuCount').textContent = `检测到 ${gpuCount} 块 GPU`;
|
||||
}
|
||||
|
||||
// 更新总显存
|
||||
document.getElementById('gpuTotalMemory').textContent = `${totalUsedMemory.toFixed(1)}/${totalMemory} GB`;
|
||||
const gpuTotalMem = document.getElementById('gpuTotalMemory');
|
||||
if (gpuTotalMem) {
|
||||
gpuTotalMem.textContent = `${totalUsedMemory.toFixed(1)}/${totalMemory} GB`;
|
||||
}
|
||||
}
|
||||
|
||||
// 启动硬件监控自动刷新
|
||||
|
||||
Reference in New Issue
Block a user