From 57fa7036dc84f0534710e2b05a74115392b278e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 3 Nov 2023 11:51:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A3=81=E7=9B=98=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E7=BB=9F=E8=AE=A1=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/node_status_executor.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/nodes/node_status_executor.go b/internal/nodes/node_status_executor.go index d9f1845..361b235 100644 --- a/internal/nodes/node_status_executor.go +++ b/internal/nodes/node_status_executor.go @@ -223,6 +223,7 @@ func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) { // 当前TeaWeb所在的fs var rootFS = "" var rootTotal = uint64(0) + var totalUsed = uint64(0) if lists.ContainsString([]string{"darwin", "linux", "freebsd"}, runtime.GOOS) { for _, p := range partitions { if p.Mountpoint == "/" { @@ -230,6 +231,7 @@ func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) { usage, _ := disk.Usage(p.Mountpoint) if usage != nil { rootTotal = usage.Total + totalUsed = usage.Used } break } @@ -237,7 +239,6 @@ func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) { } var total = rootTotal - var totalUsage = uint64(0) var maxUsage = float64(0) for _, partition := range partitions { if runtime.GOOS != "windows" && !strings.Contains(partition.Device, "/") && !strings.Contains(partition.Device, "\\") { @@ -256,16 +257,16 @@ func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) { if partition.Mountpoint != "/" && (usage.Total != rootTotal || total == 0) { total += usage.Total - } - totalUsage += usage.Used - if usage.UsedPercent >= maxUsage { - maxUsage = usage.UsedPercent - status.DiskMaxUsagePartition = partition.Mountpoint + totalUsed += usage.Used + if usage.UsedPercent >= maxUsage { + maxUsage = usage.UsedPercent + status.DiskMaxUsagePartition = partition.Mountpoint + } } } status.DiskTotal = total if total > 0 { - status.DiskUsage = float64(totalUsage) / float64(total) + status.DiskUsage = float64(totalUsed) / float64(total) } status.DiskMaxUsage = maxUsage / 100