业务系统
+355
+服务器
+diff --git a/backend/internal/handler/handler.go b/backend/internal/handler/handler.go index 6dab31f..31cb10b 100644 --- a/backend/internal/handler/handler.go +++ b/backend/internal/handler/handler.go @@ -771,18 +771,18 @@ func GetAllDeviceStatus(c *gin.Context) { allDevices := deviceStorage.GetDevices() // 查询每个设备的状态 - result := make([]map[string]interface{}, 0, len(allDevices)) - for _, device := range allDevices { - // 查询设备监控数据 - _, status, _ := globalStorage.QueryDeviceStatus(context.Background(), device.ID) + result := make([]map[string]interface{}, 0, len(allDevices)) + for _, device := range allDevices { + // 查询设备监控数据 + _, status, _ := globalStorage.QueryDeviceStatus(context.Background(), device.ID) - // 总是返回设备信息,无论是否有监控数据 - result = append(result, map[string]interface{}{ - "device_id": device.ID, - "name": device.Name, - "status": status, - }) - } + // 总是返回设备信息,无论是否有监控数据 + result = append(result, map[string]interface{}{ + "id": device.ID, + "name": device.Name, + "status": status, + }) + } c.JSON(http.StatusOK, gin.H{ "devices": result, diff --git a/backend/monitor-server b/backend/monitor-server index a059939..02631dd 100755 Binary files a/backend/monitor-server and b/backend/monitor-server differ diff --git a/backend/static/index.html b/backend/static/index.html index db092ce..b5b9473 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -197,7 +197,7 @@
无效的服务器ID
`; + } } - - loadMetrics(); } else { showContent('homeContent'); loadHomeData(); @@ -198,28 +209,24 @@ async function loadHomeData() { async function loadBusinessViewData() { try { const response = await fetch(`${API_BASE_URL}/devices/`); - const data = await response.json(); - let devices = data.devices || []; - - // 如果没有设备,使用模拟数据 - if (devices.length === 0) { - devices = [ - { id: 'device-1', name: '服务器1', ip: '192.168.1.100' }, - { id: 'device-2', name: '服务器2', ip: '192.168.1.101' } - ]; + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); } + const data = await response.json(); + const devices = data.devices || []; renderBusinessView(devices); } catch (error) { console.error('加载业务视图数据失败:', error); - // 使用模拟数据 - const mockDevices = [ - { id: 'device-1', name: 'LIS', ip: '192.129.6.108', os: 'Linux', status: 'P1' }, - { id: 'device-2', name: '互联网医院', ip: '192.129.6.57', os: 'Linux', status: 'P3' }, - { id: 'device-3', name: 'HIS', ip: '192.129.51.21', os: 'Windows', status: 'P2' }, - { id: 'device-4', name: 'OA', ip: '192.129.6.42', os: 'Linux', status: 'P2' } - ]; - renderBusinessView(mockDevices); + // 只显示错误信息,不使用模拟数据 + const tableBody = document.getElementById('businessViewTableBody'); + if (tableBody) { + tableBody.innerHTML = ` +加载服务器列表失败
+${device.ip || 'N/A'}
CPU使用率
-0.0%
+${cpuUsage}%
+磁盘使用率
+${diskUsage}%
内存使用率
-0.0%
-磁盘使用率
-0.0%
-${memoryUsage}%
网络流量
-0.0 MB/s
+${networkTraffic} MB/s
服务器名称: 服务器 ${deviceId} | IP地址: 192.168.1.${deviceId}
`; + serverInfoDisplay.innerHTML = `加载服务器信息失败
`; } } } @@ -2388,15 +2439,11 @@ function updateInterfaceDropdown(networkData) { } }); } else { - // 如果没有按网卡分组的数据,使用模拟网卡名称 - // 这里可以根据实际情况修改,比如从其他地方获取网卡名称列表 - const mockInterfaces = ['eth0', 'eth1', 'lo']; - mockInterfaces.forEach(iface => { - const option = document.createElement('option'); - option.value = iface; - option.textContent = iface; - select.appendChild(option); - }); + // 如果没有按网卡分组的数据,显示"所有接口"选项 + const option = document.createElement('option'); + option.value = 'all'; + option.textContent = '所有接口'; + select.appendChild(option); } // 恢复当前选中的值 @@ -2919,15 +2966,7 @@ function showContent(contentId) { } } -// 跳转到服务器监控详情页面 -function goToServerMonitor(deviceId) { - state.currentDeviceID = deviceId; - window.location.hash = `#serverMonitor/${deviceId}`; - // 加载选中设备的监控数据 - setTimeout(() => { - loadMetrics(); - }, 100); -} +// 注意:此函数已被更新的goToServerMonitor函数替代,保留用于兼容 // 初始化图表选项卡 diff --git a/static_backup/home.html b/static_backup/home.html new file mode 100644 index 0000000..db41574 --- /dev/null +++ b/static_backup/home.html @@ -0,0 +1,102 @@ + + + + + +业务系统
+服务器
+