diff --git a/packages/helpers/helpers.go b/packages/helpers/helpers.go index e03727ff..225d1b29 100644 --- a/packages/helpers/helpers.go +++ b/packages/helpers/helpers.go @@ -108,15 +108,17 @@ func Cut(begin, end, str string) string { // MonitoringInfo 监控信息 type MonitoringInfo struct { - Cpus []cpu.InfoStat `json:"cpus"` - Percent []float64 `json:"percent"` - Load *load.AvgStat `json:"load"` - Host *host.InfoStat `json:"host"` - Mem *mem.VirtualMemoryStat `json:"mem"` - Swap *mem.SwapMemoryStat `json:"swap"` - Net []net.IOCountersStat `json:"net"` - Disk map[string]disk.IOCountersStat `json:"disk"` - Process []*process.Process `json:"process"` + Cpus []cpu.InfoStat `json:"cpus"` + Percent []float64 `json:"percent"` + Load *load.AvgStat `json:"load"` + Host *host.InfoStat `json:"host"` + Mem *mem.VirtualMemoryStat `json:"mem"` + Swap *mem.SwapMemoryStat `json:"swap"` + Net []net.IOCountersStat `json:"net"` + DiskIO map[string]disk.IOCountersStat `json:"disk_io"` + Disk []disk.PartitionStat `json:"disk"` + DiskUsage map[string]*disk.UsageStat `json:"disk_usage"` + Process []*process.Process `json:"process"` } // GetMonitoringInfo 获取监控数据 @@ -129,9 +131,19 @@ func GetMonitoringInfo() MonitoringInfo { res.Mem, _ = mem.VirtualMemory() res.Swap, _ = mem.SwapMemory() res.Net, _ = net.IOCounters(true) - res.Disk, _ = disk.IOCounters() + res.DiskIO, _ = disk.IOCounters() + res.Disk, _ = disk.Partitions(true) res.Process, _ = process.Processes() + res.DiskUsage = make(map[string]*disk.UsageStat) + for _, partition := range res.Disk { + if strings.HasPrefix(partition.Mountpoint, "/dev") || strings.HasPrefix(partition.Mountpoint, "/sys") || strings.HasPrefix(partition.Mountpoint, "/proc") || strings.HasPrefix(partition.Mountpoint, "/run") || strings.HasPrefix(partition.Mountpoint, "/boot") || strings.HasPrefix(partition.Mountpoint, "/usr") { + continue + } + usage, _ := disk.Usage(partition.Mountpoint) + res.DiskUsage[partition.Mountpoint] = usage + } + return res } diff --git a/public/res/views/index.html b/public/res/views/index.html index 3dd2da14..34f66557 100644 --- a/public/res/views/index.html +++ b/public/res/views/index.html @@ -1,7 +1,7 @@
@@ -17,7 +17,7 @@ Date: 2022-11-30 WeAvatar - 互联网公共头像服务 - WePublish - WordPress的本土化版本 + WePublish - WordPress 本土化平台
@@ -98,7 +98,6 @@ Date: 2022-11-30 -
基本信息
@@ -134,7 +133,30 @@ Date: 2022-11-30
-
+
+
+
+ 磁盘信息 + +
+
+ +
+
+
+
关于面板 @@ -142,7 +164,7 @@ Date: 2022-11-30
-

开发组祝大家2023新年快乐!新的一年永无Bug,永不宕机!

+

开发组祝大家2023端午快乐!永无Bug,永不宕机!

欢迎您使用耗子Linux面板。如遇到问题/Bug,可通过 var home_timer var uptime_1 = '获取中', uptime_5 = '获取中', uptime_15 = '获取中' + var net_send = 0, net_recv = 0, net_send_last = 0, net_recv_last = 0 function formatBytes (size) { size = Number(size) @@ -177,7 +200,7 @@ Date: 2022-11-30 return num.toFixed(2) + '%' } - function refresh_home_info () { + function refresh_home_info (first = false) { layui.use(['index', 'jquery', 'admin'], function () { let $ = layui.jquery , admin = layui.admin @@ -209,9 +232,26 @@ Date: 2022-11-30 element.progress('uptime_1', uptime_1) element.progress('uptime_5', uptime_5) + // 计算网卡流量 + for (let i = 0; i < result.data.net.length; i++) { + if (result.data.net[i].name === 'lo') { + continue + } + net_send += result.data.net[i].bytesSent + net_recv += result.data.net[i].bytesRecv + } + if (first) { + net_send_last = net_send + net_recv_last = net_recv + } + $('#home_net_now').html(formatBytes((net_send - net_send_last) / 3) + '/s / ' + formatBytes((net_recv - net_recv_last) / 3) + '/s') + $('#home_net_total').html(formatBytes(net_send) + ' / ' + formatBytes(net_recv)) + net_send_last = net_send + net_recv_last = net_recv + net_send = 0 + net_recv = 0 + cpu_info = result.data.cpus[0].modelName + ' ' + cores + '线程' - //$('#home_net_total').html(result.data.tx_total + ' / ' + result.data.rx_total) - //$('#home_net_now').html(result.data.tx_now + '/s / ' + result.data.rx_now + '/s') $('#home_cpu').text(cpu_info) $('#home_mem').text('使用 ' + formatBytes(result.data.mem.used) + ' / ' + '总计 ' + formatBytes(result.data.mem.total)) element.render('progress') @@ -221,7 +261,7 @@ Date: 2022-11-30 } // 先执行一次 - refresh_home_info() + refresh_home_info(true) // 然后设置个定时器3s一次刷新 clearInterval(home_timer) home_timer = setInterval(refresh_home_info, 3000) @@ -229,7 +269,6 @@ Date: 2022-11-30 layui.use(['index', 'jquery', 'admin', 'carousel'], function () { let $ = layui.jquery , admin = layui.admin - , element = layui.element , carousel = layui.carousel carousel.render({ elem: '#ad1-carousel'